-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 3.1 KB
/
tag.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: "Add version tag on push to main or test"
on:
push:
branches:
- main
- test
jobs:
tag-on-push:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
statuses: read
# Additional permissions are a workaround for gh cli trying to read projects during edit
checks: read
repository-projects: read
issues: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # used by version (git) operations to find the most recent tag outside of this branch
- name: Check files changed
id: check-changes
run: |
# git diff --name-status ${{ github.event.before }}..${{ github.event.after }}
diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} | wc -l)
echo "diffs=$diffs"
if ((diffs > 0)); then
echo "setting has_diff true"
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "setting has_diff false"
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Get next version
uses: reecetech/[email protected]
id: version
if: ${{ steps.check-changes.outputs.has_diff == 'true' }}
with:
scheme: semver
increment: minor
# TODO: Could we use increment patch when bugfixes land on dev?
- name: Create tag
uses: actions/github-script@v7
if: ${{ steps.check-changes.outputs.has_diff == 'true' }}
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ steps.version.outputs.version }}',
sha: context.sha
})
- name: Update promotion PR (test)
id: update-pr-test
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ steps.check-changes.outputs.has_diff == 'true' && github.ref == 'refs/heads/test' }}
run: |
# Debug output:
gh pr list --json baseRefName,headRefName,number
pr_number=$(gh pr list --json baseRefName,headRefName,number --jq 'map(select(.baseRefName == "main" and .headRefName == "test")) | .[0].number')
echo "pr_number=$pr_number"
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
gh pr edit $pr_number --title "Merge test changes to main - ${{ steps.version.outputs.v-version }}"
- name: Create or update version tag comment in promotion PR (test)
uses: im-open/[email protected]
if: ${{ steps.check-changes.outputs.has_diff == 'true' && github.ref == 'refs/heads/test' }}
with:
pr-number: ${{ steps.update-pr-test.outputs.pr_number }}
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-identifier: "current-tag"
comment-content: "🕔 This PR currently contains the tag: ${{ steps.version.outputs.v-version }} which supersedes ${{ steps.version.outputs.current-v-version }}"