|
7 | 7 | runs-on: ubuntu-latest
|
8 | 8 |
|
9 | 9 | steps:
|
10 |
| - - name: Dump GitHub context |
| 10 | + # Get the version of _this_ repository that is in use so that we can use |
| 11 | + # sidecar scripts |
| 12 | + - id: workflow-parsing |
| 13 | + name: Get SHA of reusuable workflow |
11 | 14 | env:
|
12 |
| - GITHUB_CONTEXT: ${{ toJson(github) }} |
13 |
| - run: echo "$GITHUB_CONTEXT" |
| 15 | + REPO: ${{ github.repository }} |
| 16 | + RUN_ID: ${{ github.run_id }} |
| 17 | + GH_TOKEN: ${{ github.token }} |
| 18 | + run: | |
| 19 | + ACTION_DATA=$(gh api "repos/$REPO/actions/runs/$RUN_ID") |
| 20 | + echo "::debug::$ACTION_DATA" |
| 21 | + SHA=$(echo "$ACTION_DATA" | jq -r '.referenced_workflows | .[] | select(.path | startswith("uclahs-cds/tool-create-release")).sha') |
| 22 | + echo "SHA=$SHA" >> "$GITHUB_OUTPUT" |
| 23 | +
|
| 24 | + - name: Checkout reusable repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + repository: uclahs-cds/tool-create-release |
| 28 | + ref: ${{ steps.workflow-parsing.outputs.SHA }} |
| 29 | + token: ${{ secrets.UCLAHS_CDS_REPO_READ_TOKEN }} |
14 | 30 |
|
15 | 31 | - id: parse-version
|
16 | 32 | uses: actions/github-script@v7
|
17 | 33 | with:
|
18 | 34 | script: |
|
19 |
| - // Sanity-check that this was called from an appropriate merge event and |
20 |
| - // extract the version number embedded in the branch name. |
21 |
| -
|
22 |
| - if (context.eventName !== 'pull_request') { |
23 |
| - core.setFailed('Workflow requires pull_request events') |
24 |
| - process.exit() |
25 |
| - } |
26 |
| -
|
27 |
| - if (!context.payload.pull_request.merged || context.payload.pull_request.state !== 'closed') { |
28 |
| - core.setFailed('Workflow should only be called on merged and closed PRs') |
29 |
| - process.exit() |
30 |
| - } |
31 |
| -
|
32 |
| - if (!['Bot', 'Organization'].includes(context.payload.pull_request.user.type)) { |
33 |
| - core.setFailed('Workflow should only be called for Bot- or Organization-generated release PRs') |
34 |
| - process.exit() |
35 |
| - } |
36 |
| -
|
37 |
| - // This regex needs to kept in-sync with the pattern in create-release-pr.yaml |
38 |
| - const regex = /^automation-create-release-(.*)$/i |
39 |
| - const parsed_version = context.payload.pull_request.head.ref.match(regex) |
40 |
| -
|
41 |
| - if (!parsed_version || !parsed_version[1].length) { |
42 |
| - core.setFailed('Workflow not called from an appropriate branch name') |
43 |
| - process.exit() |
44 |
| - } |
45 |
| -
|
46 |
| - const new_version = parsed_version[1] |
47 |
| -
|
48 |
| - github.rest.repos.createRelease({ |
49 |
| - owner: context.repo.owner, |
50 |
| - repo: context.repo.repo, |
51 |
| - tag_name: `v${new_version}`, |
52 |
| - target_commitish: context.payload.pull_request.merge_commit_sha, |
53 |
| - name: `Release ${new_version}`, |
54 |
| - draft: true, |
55 |
| - generate_release_notes: true, |
56 |
| - body: `Automatically generated after merging #${context.payload.number}.` |
57 |
| - }) |
| 35 | + const script = require('./scripts/create-tag.js') |
| 36 | + await script({github, context, core}) |
0 commit comments