-
-
Notifications
You must be signed in to change notification settings - Fork 39
182 lines (149 loc) · 6.84 KB
/
comment_actions.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: "Custom / Actions"
on:
issue_comment:
types: [created]
jobs:
custom_actions:
if: github.event_name == 'issue_comment' &&
(startsWith(github.event.comment.body, '/release') ||
startsWith(github.event.comment.body, '/renovate')) &&
github.event.comment.user.login == 'MaxWinterstein'
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
## Commons
- name: Update comment with workflow URL
run: |
# Get the current workflow run URL
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Build the new comment content
UPDATED_COMMENT="[Workflow run triggered! 🚀](${RUN_URL})"
# Use curl to update the comment
curl -X PATCH \
-H "Authorization: Bearer ${{ secrets.RENOVATE_ACTION }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }} \
-d "{\"body\": \"${UPDATED_COMMENT}\"}"
# Add rocket reaction
curl -X POST \
-H "Authorization: token ${{ secrets.RENOVATE_ACTION }}" \
-H "Accept: application/vnd.github.squirrel-girl-preview+json" \
-d '{"content": "rocket"}' \
https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions
- name: Checkout code
uses: actions/checkout@v4
## Renovate
- name: Self-hosted Renovate
if: startsWith(github.event.comment.body, '/renovate')
uses: renovatebot/[email protected]
with:
token: ${{ secrets.RENOVATE_TOKEN }}
configurationFile: .github/renovate.json5
env:
RENOVATE_REPOSITORIES: "['${{ github.repository }}']"
RENOVATE_ALLOWED_POST_UPGRADE_COMMANDS: ".*"
# if: github.event_name == 'issue_comment' && (
# startsWith(github.event.comment.body, '/release')
## Version bump
- name: Get the pull request details - if there is one
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/release')
id: pr-details
run: |
PR_NUMBER=${{ github.event.issue.number }}
# Fetch PR details using GitHub API
PR_DATA=$(gh pr view $PR_NUMBER --json headRefName,title --jq '{branchName: .headRefName, title: .title}')
BRANCH_NAME=$(echo $PR_DATA | jq -r .branchName)
TITLE=$(echo $PR_DATA | jq -r .title)
echo "Branch name: $BRANCH_NAME"
echo "Title: $TITLE"
echo "::set-output name=branch_name::$BRANCH_NAME"
echo "::set-output name=title::$TITLE"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get mentioned Addon
if: startsWith(github.event.comment.body, '/release')
id: get_addon
run: |
comment_body="${{ github.event.comment.body }}"
PR_TITLE="${{ steps.pr-details.outputs.title }}"
ADDON=''
# Check if the PR title has an add-on mentioned
if [[ "$PR_TITLE" =~ \[([a-zA-Z0-9_-]+)\] ]]; then
ADDON="${BASH_REMATCH[1]}"
echo "Mentioned Addon from PR Title: $ADDON"
elif [[ "$comment_body" =~ /release[[:space:]]([a-zA-Z0-9_-]+) ]]; then
ADDON="${BASH_REMATCH[1]}"
echo "Mentioned Addon from Comment Body: $ADDON"
else
echo "No valid add-on found"
exit 1
fi
echo "::set-output name=addon::$ADDON"
- name: Checkout the pull request branch
if: startsWith(github.event.comment.body, '/release')
uses: actions/checkout@v4
with:
ref: ${{ steps.pr-details.outputs.branch_name }}
- name: Extract version from config.yaml
if: startsWith(github.event.comment.body, '/release')
id: get_version
uses: mikefarah/[email protected]
with:
cmd: yq '.version' ${{ steps.get_addon.outputs.addon }}/config.yaml
- name: Increment version
if: startsWith(github.event.comment.body, '/release')
id: increment_version
run: |
# Read current version and split it into major, minor, patch, and optionally build components
IFS='.' read -r MAJOR MINOR PATCH BUILD <<< "${{ steps.get_version.outputs.result }}"
# Increment the MINOR version
MINOR=$((MINOR + 1))
# BUILD=0 # Reset build number when MINOR is incremented
PATCH=0 # Reset patch number when MINOR is incremented
# Construct the new version
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
# Append build if it exists
if [[ -n $BUILD ]]; then
NEW_VERSION="$NEW_VERSION.0"
fi
# Print the updated version for logging purposes
echo "Bumped version to $NEW_VERSION"
echo "::set-output name=new_version::$NEW_VERSION"
- name: Bump version in config.yaml
if: startsWith(github.event.comment.body, '/release')
uses: mikefarah/[email protected]
with:
cmd: yq -i '.version = "${{ steps.increment_version.outputs.new_version }}"' ${{ steps.get_addon.outputs.addon }}/config.yaml
- name: Install uv
if: startsWith(github.event.comment.body, '/release')
uses: astral-sh/setup-uv@v3
with:
# Install a specific version of uv.
version: "0.4.20"
- name: Set up Python
if: startsWith(github.event.comment.body, '/release')
run: uv python install
- name: Install the project
if: startsWith(github.event.comment.body, '/release')
run: uv sync --all-extras --dev
- name: Build towncrier
if: startsWith(github.event.comment.body, '/release')
run: |
# mv "${{ steps.get_addon.outputs.addon }}/CHANGELOG.md" CHANGELOG.md
uv run towncrier build --yes --dir "${{ steps.get_addon.outputs.addon }}/" --version "${{ steps.increment_version.outputs.new_version }}" --config pyproject.toml
# mv CHANGELOG.md "${{ steps.get_addon.outputs.addon }}/CHANGELOG.md"
- name: Push changes
if: startsWith(github.event.comment.body, '/release')
uses: stefanzweifel/git-auto-commit-action@v5
with:
token: ${{ secrets.RENOVATE_ACTION }}
## Common
- name: Delete the comment
run: |
curl -X DELETE \
-H "Authorization: token ${{ secrets.RENOVATE_ACTION }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}