|
| 1 | +name: Upload artifact |
| 2 | +description: Wrapper around GitHub's official action, with additional archiving before upload |
| 3 | + |
| 4 | +# PROCESS |
| 5 | +# |
| 6 | +# 1. Creates tarball excluding .git files |
| 7 | +# 2. Uploads tarball using actions/upload-artifact action, fail CI job if no file is found |
| 8 | +# 3. Remove archive after uploading it. |
| 9 | + |
| 10 | +# NOTES |
| 11 | +# |
| 12 | +# Upload-artifact and download-artifact takes ~2m40s to upload 8MB |
| 13 | +# so this is custom action cuts down the entire operation to 1s |
| 14 | +# by uploading/extracting a tarball while relying on the official upload-artifact/download-artifact actions |
| 15 | +# |
| 16 | + |
| 17 | +# USAGE |
| 18 | +# |
| 19 | +# NOTE: Meant to be used with ./.github/actions/download-artifact |
| 20 | +# |
| 21 | +# - name: Upload sealed source code |
| 22 | +# uses: ./.github/actions/upload-artifact |
| 23 | +# with: |
| 24 | +# name: ${{ steps.integrity.outputs.INTEGRITY_HASH }} |
| 25 | +# path: . |
| 26 | + |
| 27 | +# https://github.com/actions/upload-artifact/blob/main/action.yml |
| 28 | +inputs: |
| 29 | + name: |
| 30 | + description: Artifact name |
| 31 | + required: true |
| 32 | + path: |
| 33 | + description: > |
| 34 | + A file, directory or wildcard pattern that describes what to upload. |
| 35 | +
|
| 36 | + You can pass multiple paths separated by space (e.g., dir1 dir2 file.txt). |
| 37 | +
|
| 38 | + Paths and wildcard patterns must be tar command compatible. |
| 39 | + required: true |
| 40 | + retention-days: |
| 41 | + description: > |
| 42 | + Artifact retention in days. By default 1 day, max of 90 days, and 0 honours default repo retention. |
| 43 | +
|
| 44 | + You can change max days in the repository settings. |
| 45 | + required: false |
| 46 | + default: "1" |
| 47 | + if-no-files-found: |
| 48 | + description: > |
| 49 | + Action to perform if no files are found: warn, error, ignore. By default, it fails fast with 'error'. |
| 50 | +
|
| 51 | + Options: |
| 52 | + warn: Output a warning but do not fail the action |
| 53 | + error: Fail the action with an error message |
| 54 | + ignore: Do not output any warnings or errors, the action does not fail |
| 55 | + required: false |
| 56 | + default: error |
| 57 | + |
| 58 | +runs: |
| 59 | + using: composite |
| 60 | + steps: |
| 61 | + - name: Archive artifacts |
| 62 | + run: | |
| 63 | + tar --exclude-vcs \ |
| 64 | + -cvf "${ARCHIVE}" "${PATH_TO_ARCHIVE}" |
| 65 | + env: |
| 66 | + ARCHIVE: ${{ inputs.name }}.tar |
| 67 | + PATH_TO_ARCHIVE: ${{ inputs.path }} |
| 68 | + shell: bash |
| 69 | + |
| 70 | + - name: Upload artifacts |
| 71 | + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 |
| 72 | + with: |
| 73 | + if-no-files-found: ${{ inputs.if-no-files-found }} |
| 74 | + name: ${{ inputs.name }} |
| 75 | + path: ${{ inputs.name }}.tar |
| 76 | + retention-days: ${{ inputs.retention-days }} |
| 77 | + |
| 78 | + - name: Remove archive |
| 79 | + run: rm -f "${ARCHIVE}" |
| 80 | + env: |
| 81 | + ARCHIVE: ${{ inputs.name }}.tar |
| 82 | + shell: bash |
0 commit comments