forked from ansible/awx-ee
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from influxdata/tag_merge
Generate tag on PR merge
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: "Create Tag on Pull Request merge" | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- main | ||
|
||
jobs: | ||
TagMerge: | ||
name: Tag on Pull Request merge | ||
permissions: | ||
issues: write | ||
pull-requests: write | ||
contents: write | ||
|
||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
steps: | ||
- name: Generate Tag | ||
id: tagged | ||
run: | | ||
echo $(curl \ | ||
--silent \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | ||
"https://api.github.com/repos/${{ github.repository }}/tags" \ | ||
| jq -r '.[].name |= sub("-rc0|v"; "";"g") | select(length > 1) | max_by(.name) | .name' \ | ||
| awk ' | ||
function inc(s){ | ||
split(s, a, ".") | ||
a[3]++ | ||
if (a[3]>=10){ | ||
a[2]++;a[3]=0 | ||
} | ||
if (a[2]>=10){ | ||
a[1]++;a[2]=0 | ||
} | ||
return a[1]"."a[2]"."a[3] | ||
} | ||
{ print "newtag="inc($1) }') >> $GITHUB_OUTPUT | ||
- name: Create new tag in github | ||
id: createtag | ||
run: | | ||
echo tag_sha=$(curl \ | ||
--silent \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | ||
"https://api.github.com/repos/${{ github.repository }}/git/tags" \ | ||
-d '{"tag":"v${{ steps.tagged.outputs.newtag }}","message":"New release from github actions","object":"${{ github.sha }}","type":"commit"}' \ | ||
| jq -r '.sha') >> $GITHUB_OUTPUT | ||
- name: Create ref tag in github | ||
id: createreftag | ||
run: | | ||
curl \ | ||
--silent \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | ||
"https://api.github.com/repos/${{ github.repository }}/git/refs" \ | ||
-d '{"ref": "refs/tags/v${{ steps.tagged.outputs.newtag }}", "sha": "${{ steps.createtag.outputs.tag_sha}}" }' | ||
- name: Add PR comment with new tag info | ||
run: | | ||
curl \ | ||
--silent \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | ||
"${{ github.event.pull_request._links.comments.href }}" \ | ||
-d '{"body":"Created tag v${{ steps.tagged.outputs.newtag }}"}' |