-
Notifications
You must be signed in to change notification settings - Fork 39
182 lines (162 loc) · 7.69 KB
/
releaser.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Release Tagging
on:
pull_request_target:
types: [opened]
push:
branches:
- main
permissions:
contents: write # Necessary for accessing and modifying repository content
pull-requests: write # Necessary for interacting with pull requests
actions: write # Necessary for triggering other workflows
jobs:
tag-discussion:
if: github.event_name == 'pull_request_target' && github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository)
repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo
- name: Calculate new versions
id: calculate_versions
run: |
git fetch --tags
LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="0.0.0"
fi
MAJOR=$(echo $LATEST_TAG | cut -d. -f1)
MINOR=$(echo $LATEST_TAG | cut -d. -f2)
PATCH=$(echo $LATEST_TAG | cut -d. -f3)
NEW_PATCH_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
NEW_MINOR_VERSION="$MAJOR.$((MINOR + 1)).0"
NEW_MAJOR_VERSION="$((MAJOR + 1)).0.0"
echo "patch_version=$NEW_PATCH_VERSION" >> $GITHUB_OUTPUT
echo "minor_version=$NEW_MINOR_VERSION" >> $GITHUB_OUTPUT
echo "major_version=$NEW_MAJOR_VERSION" >> $GITHUB_OUTPUT
- name: Start Discussion for Tagging
uses: peter-evans/create-or-update-comment@v2
id: comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Tagging Options
Should a new tag be published when this PR is merged?
- 👍 for **Patch** ${{ steps.calculate_versions.outputs.patch_version }} update
- 🎉 for **Minor** ${{ steps.calculate_versions.outputs.minor_version }} update
- 🚀 for **Major** ${{ steps.calculate_versions.outputs.major_version }} update
determine-tag:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Find the Merged Pull Request
id: find_pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BASE_BRANCH="main"
RECENT_PR=$(gh pr list --state closed --base $BASE_BRANCH --json number,title,closedAt --jq '.[] | select(.closedAt >= "'$(date -u -d '1 minute ago' +%Y-%m-%dT%H:%M:%SZ)'") | {number, title}')
echo "RECENT_PR=$RECENT_PR" >> $GITHUB_ENV
echo "PR_NUMBER=$(echo $RECENT_PR | jq -r '.number')" >> $GITHUB_ENV
- name: Fetch latest stable tag (excluding prerelease tags)
id: get_latest_tag
run: |
git fetch --tags
LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="0.0.0"
fi
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Determine the next version based on comments
id: determine_version
if: env.PR_NUMBER != ''
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_TAG=${{ steps.get_latest_tag.outputs.latest_tag }}
MAJOR=$(echo $LATEST_TAG | cut -d. -f1)
MINOR=$(echo $LATEST_TAG | cut -d. -f2)
PATCH=$(echo $LATEST_TAG | cut -d. -f3)
# Define allowed users as a JSON array
ALLOWED_USERS=$(cat MAINTAINERS.txt | jq -R -s -c 'split("\n")[:-1]')
echo "Maintainers list: $ALLOWED_USERS"
# Fetch reactions and filter by allowed users
REACTION=$(gh api graphql -f query='
query {
repository(owner:"${{ github.repository_owner }}", name:"${{ github.event.repository.name }}") {
pullRequest(number: '${PR_NUMBER}') {
comments(last: 100) {
nodes {
body
id
reactions(last: 100) {
nodes {
content
user {
login
}
}
}
}
}
}
}
}' | jq -r --argjson allowed_users "$ALLOWED_USERS" '
.data.repository.pullRequest.comments.nodes[] |
select(.body | contains("## Tagging Options")) |
.reactions.nodes[] |
select(.user.login | IN($allowed_users[])) |
.content'
)
# Print the reaction to debug
echo "Captured reaction: $REACTION"
# Convert reaction to uppercase to handle any case inconsistencies
REACTION=$(echo "$REACTION" | tr '[:lower:]' '[:upper:]')
# Determine the new tag version based on the allowed reactions
if [[ "$REACTION" == *"ROCKET"* ]]; then
NEW_TAG="$((MAJOR + 1)).0.0"
elif [[ "$REACTION" == *"HOORAY"* ]]; then
NEW_TAG="$MAJOR.$((MINOR + 1)).0"
elif [[ "$REACTION" == *"THUMBS_UP"* ]]; then # Ensure thumbs up reaction is correctly identified
NEW_TAG="$MAJOR.$MINOR.$((PATCH + 1))"
else
echo "No valid reactions found for version bump. Exiting."
exit 0
fi
echo "new_version=$NEW_TAG" >> $GITHUB_OUTPUT
- name: Update deno.json Version
if: steps.determine_version.outputs.new_version != ''
run: |
jq --arg new_version "${{ steps.determine_version.outputs.new_version }}" '.version = $new_version' deno.json > tmp.$$.json && mv tmp.$$.json deno.json
jq --arg new_version "${{ steps.determine_version.outputs.new_version }}" '.version = $new_version' ./scripts/deno.json > tmp.$$.json && mv tmp.$$.json ./scripts/deno.json
jq --arg new_version "${{ steps.determine_version.outputs.new_version }}" '.version = $new_version' ./dev/deno.json > tmp.$$.json && mv tmp.$$.json ./dev/deno.json
git config user.name "decobot"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add deno.json ./scripts/deno.json ./dev/deno.json
git commit -m "Update version to ${{ steps.determine_version.outputs.new_version }}"
git push origin main
- name: Create and Push Tag
if: steps.determine_version.outputs.new_version != ''
run: |
git tag ${{ steps.determine_version.outputs.new_version }}
git push origin ${{ steps.determine_version.outputs.new_version }}
- name: Trigger Release Workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
- name: Trigger Publish Workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/publish.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'