Skip to content

Commit

Permalink
Use composite action for determining next tag
Browse files Browse the repository at this point in the history
  • Loading branch information
katybaulch committed Mar 6, 2024
1 parent 2f7d3f5 commit 1d8b6f8
Showing 1 changed file with 4 additions and 52 deletions.
56 changes: 4 additions & 52 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,64 +23,16 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}

# Expose step outputs as job outputs
outputs:
new_tag: ${{ steps.determine_next_tag.outputs.new_tag }}

steps:
- uses: actions/github-script@v6
id: get_pr_data
with:
script: |
return (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})
).data[0];
- uses: actions/checkout@v4
- uses: fregante/setup-git-user@v2

- name: Debug
run: |
echo ${{ github.event_name }}
echo ${{ github.ref }}
echo ${{ github.event.pull_request.head.ref }}
echo ${{ github.event.pull_request.base.ref }}
echo ${{ github.event }}
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"

- name: Determine new tag version
id: determine_next_tag
# User controlled input needs to be santitised beforehand e.g., by adding an
# intermediate env var to prevent the workflow being exposed to a critical
# command injection attack
env:
PR_BODY: "${{ fromJson(steps.get_pr_data.outputs.result).body }}"
PR_NUMBER: "${{ fromJson(steps.get_pr_data.outputs.result).number }}"
run: |
echo "Attempting to auto-tag merge commit"
script_output=$("${{ github.action_path }}/.github/auto-tag.sh" "${PR_BODY}" "${PR_NUMBER}")
if $? != 0; then
exit 1
fi
new_tag=$(echo "${script_output}" | tail -n 1)
echo "New tag: ${new_tag}"
echo "new_tag=${new_tag}" >> "$GITHUB_OUTPUT"
uses: climatepolicyradar/get-next-tag-from-pr-body@main

- name: Echo next tag
run: echo ${{ steps.determine_next_tag.outputs.new_tag }}

semver:
needs: git
Expand Down

0 comments on commit 1d8b6f8

Please sign in to comment.