|
| 1 | +--- |
| 2 | +name: 'Checkout and use Build' |
| 3 | +description: 'checks-out the given commit and fetches the build artifact' |
| 4 | +author: 'Mr. Walls' |
| 5 | +branding: |
| 6 | + icon: 'chevron-down' |
| 7 | + color: 'blue' |
| 8 | +inputs: |
| 9 | + sha: |
| 10 | + description: | |
| 11 | + The commit to checkout and fetch build artifacts for. When running this action on github.com, |
| 12 | + the default value is sufficient. |
| 13 | + required: true |
| 14 | + default: ${{ github.server_url == 'https://github.com' && github.sha || 'HEAD' }} |
| 15 | + path: |
| 16 | + description: | |
| 17 | + Path to setup. When running this action on github.com, the default value |
| 18 | + is sufficient. |
| 19 | + required: true |
| 20 | + default: ${{ github.server_url == 'https://github.com' && github.workspace || '' }} |
| 21 | + token: |
| 22 | + description: | |
| 23 | + The token used to authenticate when fetching Python distributions from |
| 24 | + https://github.com/actions/python-versions. When running this action on github.com, |
| 25 | + the default value is sufficient. When running on GHES, you can pass a personal access |
| 26 | + token for github.com if you are experiencing rate limiting. |
| 27 | + default: ${{ github.server_url == 'https://github.com' && github.token || '' }} |
| 28 | + required: true |
| 29 | + python-version: |
| 30 | + description: | |
| 31 | + The python version to setup. The default is to use the value of the github |
| 32 | + variable 'PYTHON_DEFAULT'. |
| 33 | + default: ${{ github.server_url == 'https://github.com' && vars.PYTHON_DEFAULT || '3.12' }} |
| 34 | + required: true |
| 35 | +outputs: |
| 36 | + branch-name: |
| 37 | + description: "The name of the branch that was checked-out" |
| 38 | + type: string |
| 39 | + value: ${{ steps.output_branch_name.outputs.branch-name || '' }} |
| 40 | + sha: |
| 41 | + description: "The SHA of the commit checked-out" |
| 42 | + type: string |
| 43 | + value: ${{ steps.output_sha.outputs.sha || 'HEAD' }} |
| 44 | + python-version: |
| 45 | + description: "The python version that was used in the run." |
| 46 | + value: ${{ steps.cp313.outputs.python-version || '' }} |
| 47 | + artifact-name: |
| 48 | + description: "The downloaded artifact-name" |
| 49 | + type: string |
| 50 | + value: "multicast-build-${{ steps.output_sha.outputs.sha }}.zip" |
| 51 | + artifact-files: |
| 52 | + description: "The downloaded artifact-files" |
| 53 | + value: ${{ steps.output_artifact_files.outputs.files }} |
| 54 | + |
| 55 | +runs: |
| 56 | + using: composite |
| 57 | + steps: |
| 58 | + - name: Checkout repository |
| 59 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 60 | + with: |
| 61 | + persist-credentials: false |
| 62 | + fetch-depth: 0 |
| 63 | + path: ${{ inputs.path }} |
| 64 | + repository: reactive-firewall/multicast |
| 65 | + token: ${{ inputs.token }} |
| 66 | + - name: "Checkout Target Commit by SHA" |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + printf "%s\n" "::group::target-commit" |
| 70 | + git checkout --force --detach ${{ inputs.sha }} -- |
| 71 | + printf "%s\n" "::endgroup::" |
| 72 | + if: ${{ (github.sha != inputs.sha) && success() }} |
| 73 | + - id: output_branch_name |
| 74 | + if: ${{ !cancelled() }} |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + printf "branch-name=%s\n" $(git name-rev --name-only HEAD | cut -d~ -f1-1) >> "$GITHUB_OUTPUT" |
| 78 | + - id: output_sha |
| 79 | + shell: bash |
| 80 | + run: printf "sha=%s\n" $(git rev-parse --verify HEAD) >> "$GITHUB_OUTPUT" |
| 81 | + - name: "Setup Python" |
| 82 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 83 | + id: cp313 |
| 84 | + with: |
| 85 | + python-version: ${{ inputs.python-version }} |
| 86 | + cache: 'pip' # caching pip dependencies |
| 87 | + if: ${{ !cancelled() }} |
| 88 | + - name: "Install Test Dependencies" |
| 89 | + run: make -j1 -f Makefile test-reqs ; |
| 90 | + - id: output_artifact_name |
| 91 | + if: ${{ success() }} |
| 92 | + shell: bash |
| 93 | + run: printf "artifact-name=%s\n" multicast-build-${{ steps.output_sha.outputs.sha }}.zip >> "$GITHUB_OUTPUT" |
| 94 | + - name: "Fetch Build Files" |
| 95 | + if: ${{ success() }} |
| 96 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 97 | + with: |
| 98 | + path: ${{ inputs.path }}/dist |
| 99 | + pattern: multicast-build-${{ steps.output_sha.outputs.sha }}.zip |
| 100 | + merge-multiple: true |
| 101 | + repository: reactive-firewall/multicast |
| 102 | + github-token: ${{ inputs.token }} |
| 103 | + - name: "Enumerate Fetched Files" |
| 104 | + id: output_artifact_files |
| 105 | + env: |
| 106 | + BUILD_MATCH_PATTERN: "dist/multicast-*-*.whl dist/multicast-*.tar.gz" |
| 107 | + SCRIPT_NAME: ".github/actions/checkout-and-rebuild/action.yml" |
| 108 | + shell: bash |
| 109 | + run: | |
| 110 | + FILES=$(git ls-files -oi --exclude-standard -- ${{ env.BUILD_MATCH_PATTERN }} ) |
| 111 | + if [ -z "$FILES" ]; then |
| 112 | + printf "::warning file=%s:: %s\n" "${SCRIPT_NAME}" "No Built files found." |
| 113 | + printf "%s\n" "files=" >> "$GITHUB_OUTPUT" |
| 114 | + else |
| 115 | + printf "%s\n" "Built files found:" |
| 116 | + printf "%s\n" "$FILES" |
| 117 | + # Replace line breaks with commas for GitHub Action Output |
| 118 | + FILES="${FILES//$'\n'/ }" |
| 119 | + printf "%s\n" "files=$FILES" >> "$GITHUB_OUTPUT" |
| 120 | + fi |
| 121 | + if: ${{ success() }} |
0 commit comments