|
| 1 | +name: Generate run metadata |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + github-event-name: |
| 6 | + type: string |
| 7 | + required: true |
| 8 | + outputs: |
| 9 | + build-tag: |
| 10 | + description: "Tag for the current workflow run" |
| 11 | + value: ${{ jobs.tags.outputs.build-tag }} |
| 12 | + previous-storage-release: |
| 13 | + description: "Tag of the last storage release" |
| 14 | + value: ${{ jobs.tags.outputs.storage }} |
| 15 | + previous-proxy-release: |
| 16 | + description: "Tag of the last proxy release" |
| 17 | + value: ${{ jobs.tags.outputs.proxy }} |
| 18 | + previous-compute-release: |
| 19 | + description: "Tag of the last compute release" |
| 20 | + value: ${{ jobs.tags.outputs.compute }} |
| 21 | + run-kind: |
| 22 | + description: "The kind of run we're currently in. Will be one of `pr`, `push-main`, `storage-rc`, `storage-release`, `proxy-rc`, `proxy-release`, `compute-rc`, `compute-release` or `merge_queue`" |
| 23 | + value: ${{ jobs.tags.outputs.run-kind }} |
| 24 | + |
| 25 | +permissions: {} |
| 26 | + |
| 27 | +jobs: |
| 28 | + tags: |
| 29 | + runs-on: ubuntu-22.04 |
| 30 | + outputs: |
| 31 | + build-tag: ${{ steps.build-tag.outputs.tag }} |
| 32 | + compute: ${{ steps.previous-releases.outputs.compute }} |
| 33 | + proxy: ${{ steps.previous-releases.outputs.proxy }} |
| 34 | + storage: ${{ steps.previous-releases.outputs.storage }} |
| 35 | + run-kind: ${{ steps.run-kind.outputs.run-kind }} |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + steps: |
| 39 | + # Need `fetch-depth: 0` to count the number of commits in the branch |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + |
| 44 | + - name: Get run kind |
| 45 | + id: run-kind |
| 46 | + env: |
| 47 | + RUN_KIND: >- |
| 48 | + ${{ |
| 49 | + false |
| 50 | + || (inputs.github-event-name == 'push' && github.ref_name == 'main') && 'push-main' |
| 51 | + || (inputs.github-event-name == 'push' && github.ref_name == 'release') && 'storage-release' |
| 52 | + || (inputs.github-event-name == 'push' && github.ref_name == 'release-compute') && 'compute-release' |
| 53 | + || (inputs.github-event-name == 'push' && github.ref_name == 'release-proxy') && 'proxy-release' |
| 54 | + || (inputs.github-event-name == 'pull_request' && github.base_ref == 'release') && 'storage-rc-pr' |
| 55 | + || (inputs.github-event-name == 'pull_request' && github.base_ref == 'release-compute') && 'compute-rc-pr' |
| 56 | + || (inputs.github-event-name == 'pull_request' && github.base_ref == 'release-proxy') && 'proxy-rc-pr' |
| 57 | + || (inputs.github-event-name == 'pull_request') && 'pr' |
| 58 | + || 'unknown' |
| 59 | + }} |
| 60 | + run: | |
| 61 | + echo "run-kind=$RUN_KIND" | tee -a $GITHUB_OUTPUT |
| 62 | +
|
| 63 | + - name: Get build tag |
| 64 | + id: build-tag |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + CURRENT_BRANCH: ${{ github.head_ref || github.ref_name }} |
| 68 | + CURRENT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} |
| 69 | + RUN_KIND: ${{ steps.run-kind.outputs.run-kind }} |
| 70 | + run: | |
| 71 | + case $RUN_KIND in |
| 72 | + push-main) |
| 73 | + echo "tag=$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT |
| 74 | + ;; |
| 75 | + storage-release) |
| 76 | + echo "tag=release-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT |
| 77 | + ;; |
| 78 | + proxy-release) |
| 79 | + echo "tag=release-proxy-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT |
| 80 | + ;; |
| 81 | + compute-release) |
| 82 | + echo "tag=release-compute-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT |
| 83 | + ;; |
| 84 | + pr|storage-rc-pr|compute-rc-pr|proxy-rc-pr) |
| 85 | + BUILD_AND_TEST_RUN_ID=$(gh run list -b $CURRENT_BRANCH -c $CURRENT_SHA -w 'Build and Test' -L 1 --json databaseId --jq '.[].databaseId') |
| 86 | + echo "tag=$BUILD_AND_TEST_RUN_ID" | tee -a $GITHUB_OUTPUT |
| 87 | + ;; |
| 88 | + *) |
| 89 | + echo "Unexpected RUN_KIND ('${RUN_KIND}'), failing to assign build-tag!" |
| 90 | + exit 1 |
| 91 | + esac |
| 92 | +
|
| 93 | + - name: Get the previous release-tags |
| 94 | + id: previous-releases |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + run: | |
| 98 | + gh api --paginate \ |
| 99 | + -H "Accept: application/vnd.github+json" \ |
| 100 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 101 | + "/repos/${GITHUB_REPOSITORY}/releases" \ |
| 102 | + | jq -f .github/scripts/previous-releases.jq -r \ |
| 103 | + | tee -a "${GITHUB_OUTPUT}" |
0 commit comments