|
| 1 | +name: "Seal and hash source code" |
| 2 | +description: "Seal and export source code as a tarball artifact along with its integrity hash" |
| 3 | + |
| 4 | +# PROCESS |
| 5 | +# |
| 6 | +# 1. Exports artifact name using Prefix + GitHub Run ID (unique for each release trigger) |
| 7 | +# 2. Compress entire source code as tarball OR given files |
| 8 | +# 3. Create and export integrity hash for tarball |
| 9 | +# 4. Upload artifact |
| 10 | +# 5. Remove archive |
| 11 | + |
| 12 | +# USAGE |
| 13 | +# |
| 14 | +# - name: Seal and upload |
| 15 | +# id: seal_source_code |
| 16 | +# uses: ./.github/actions/seal |
| 17 | +# with: |
| 18 | +# artifact_name_prefix: "source" |
| 19 | + |
| 20 | +inputs: |
| 21 | + files: |
| 22 | + description: "Files to seal separated by space" |
| 23 | + required: false |
| 24 | + artifact_name_prefix: |
| 25 | + description: "Prefix to use when exporting artifact" |
| 26 | + required: true |
| 27 | + |
| 28 | +outputs: |
| 29 | + integrity_hash: |
| 30 | + description: "Source code integrity hash" |
| 31 | + value: ${{ steps.integrity_hash.outputs.integrity_hash }} |
| 32 | + artifact_name: |
| 33 | + description: "Artifact name containTemporary branch created with staged changed" |
| 34 | + value: ${{ steps.export_artifact_name.outputs.artifact_name }} |
| 35 | + |
| 36 | +runs: |
| 37 | + using: "composite" |
| 38 | + steps: |
| 39 | + - id: adjust-path |
| 40 | + run: echo "${{ github.action_path }}" >> $GITHUB_PATH |
| 41 | + shell: bash |
| 42 | + |
| 43 | + - id: export_artifact_name |
| 44 | + name: Export final artifact name |
| 45 | + run: echo "artifact_name=${ARTIFACT_PREFIX}-${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT" |
| 46 | + env: |
| 47 | + GITHUB_RUN_ID: ${{ github.run_id }} |
| 48 | + ARTIFACT_PREFIX: ${{ inputs.artifact_name_prefix }} |
| 49 | + shell: bash |
| 50 | + |
| 51 | + # By default, create a tarball of the current directory minus .git |
| 52 | + # otherwise it breaks GH Actions when restoring it |
| 53 | + - id: compress_all |
| 54 | + if: ${{ !inputs.files }} |
| 55 | + name: Create tarball for entire source |
| 56 | + run: tar --exclude-vcs -cvf "${ARTIFACT_NAME}".tar * |
| 57 | + env: |
| 58 | + ARTIFACT_NAME: ${{ steps.export_artifact_name.outputs.artifact_name }} |
| 59 | + shell: bash |
| 60 | + |
| 61 | + # If a list of files are given, then create a tarball for those only |
| 62 | + - id: compress_selected_files |
| 63 | + if: ${{ inputs.files }} |
| 64 | + name: Create tarball for selected files |
| 65 | + run: tar --exclude-vcs -cvf "${ARTIFACT_NAME}".tar "${FILES}" |
| 66 | + env: |
| 67 | + FILES: ${{ inputs.files }} |
| 68 | + ARTIFACT_NAME: ${{ steps.export_artifact_name.outputs.artifact_name }} |
| 69 | + shell: bash |
| 70 | + |
| 71 | + - id: integrity_hash |
| 72 | + name: Create and export integrity hash for tarball |
| 73 | + run: | |
| 74 | + HASH=$(sha256sum "${ARTIFACT_NAME}.tar" | awk '{print $1}') |
| 75 | +
|
| 76 | + echo "integrity_hash=${HASH}" >> "$GITHUB_OUTPUT" |
| 77 | + env: |
| 78 | + ARTIFACT_NAME: ${{ steps.export_artifact_name.outputs.artifact_name }} |
| 79 | + shell: bash |
| 80 | + |
| 81 | + - name: Upload artifacts |
| 82 | + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 |
| 83 | + with: |
| 84 | + if-no-files-found: error |
| 85 | + name: ${{ steps.export_artifact_name.outputs.artifact_name }} |
| 86 | + path: ${{ steps.export_artifact_name.outputs.artifact_name }}.tar |
| 87 | + retention-days: 1 |
| 88 | + |
| 89 | + - name: Remove archive |
| 90 | + run: rm -f "${ARTEFACT_NAME}.tar" |
| 91 | + env: |
| 92 | + ARTIFACT_NAME: ${{ steps.export_artifact_name.outputs.artifact_name }} |
| 93 | + shell: bash |
0 commit comments