Skip to content

Commit 01e9c02

Browse files
Merge pull request #30 from IABTechLab/llp-uid2-2236-auto-pr-action
Add support for creating tags.
2 parents 1003615 + 1132706 commit 01e9c02

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
This repo contains shared actions and workflows that are consumed by the other uid2 workflows.
44

55
This simplifies the management and maintenance of the workflows.
6+
7+
## Tips and tricks
8+
9+
If you're trying to do something that should be simple, but can't find something that quite supports what you're trying to do, the [GitHub Script action](https://github.com/actions/github-script) gives you an authenticated GitHub API client and you can just provide a JavaScript script. For an example, see the "Tag commit" step in the [Commit, PR, and Merge](actions\commit-pr-and-merge\action.yaml) shared action.
10+
11+
If you use this and the script gets complicated, consider trying to find a simpler approach, or putting the script somewhere it can be maintained/tested outside of the YAML file.

actions/commit-pr-and-merge/action.yaml

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
description: 'Message for commit and PR title'
55
required: false
66
default: 'Automated update'
7+
tag:
8+
description: 'If provided, this tag is applied to the commit'
9+
required: false
710
runs:
811
using: "composite"
912
steps:
@@ -22,4 +25,22 @@ runs:
2225
env:
2326
GITHUB_TOKEN: ${{ github.token }}
2427
PR_URL: ${{ steps.create-pr.outputs.pull-request-url }}
25-
MERGE_PR_STRATEGY: ${{github.ref_protected == true && '--merge' || '--rebase' }}
28+
MERGE_PR_STRATEGY: ${{github.ref_protected == true && '--merge' || '--rebase' }}
29+
30+
- name: Tag commit
31+
uses: actions/github-script@v7
32+
if: ${{ inputs.tag }}
33+
with:
34+
script: |
35+
const pr = (await github.rest.pulls.get({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
pull_number: ${{ steps.create-pr.outputs.pull-request-number }}
39+
})).data;
40+
console.log(`Creating tag refs/tags/${{ inputs.tag }} pointing at commit SHA ${pr.merge_commit_sha}`);
41+
await github.rest.git.createRef({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
ref: 'refs/tags/${{ inputs.tag }}',
45+
sha: pr.merge_commit_sha
46+
});

0 commit comments

Comments
 (0)