forked from homeassistant-extras/pi-hole-card
-
Notifications
You must be signed in to change notification settings - Fork 1
183 lines (160 loc) · 5.68 KB
/
release-cd.yaml
File metadata and controls
183 lines (160 loc) · 5.68 KB
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
183
name: Release & Deploy
on:
push:
branches:
- 'release'
permissions:
contents: read
jobs:
check-committer:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- id: check
env:
AUTHOR_EMAIL: ${{ github.event.commits[0].author.email }}
run: |
# Allow dependabot emails specifically
if [[ "$AUTHOR_EMAIL" == *"dependabot[bot]@users.noreply.github.com"* ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
# Skip other noreply emails
elif [[ "$AUTHOR_EMAIL" == *"@users.noreply.github.com"* ]]; then
echo "should_run=false" >> $GITHUB_OUTPUT
# Allow all other emails
else
echo "should_run=true" >> $GITHUB_OUTPUT
fi
bump-version:
name: 'Bump Version and Tag'
needs: check-committer
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
newTag: ${{ steps.bump.outputs.newTag }}
if: ${{ needs.check-committer.outputs.should_run == 'true' }}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.BUILD_APP_ID }}
private-key: ${{ secrets.BUILD_PRIVATE_KEY }}
- name: 'Checkout source code'
uses: 'actions/checkout@v2'
with:
ref: ${{ github.ref }}
token: ${{ steps.app-token.outputs.token }}
- name: 'Automated Version Bump'
id: bump
uses: 'phips28/gh-action-bump-version@master'
with:
version-type: 'minor'
commit-message: 'chore: bumps version to {{version}}'
bump-policy: 'ignore'
skip-push: 'true'
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: 'Create Tags and package version'
run: |
git push --follow-tags
git push --tags
create-release:
name: 'Create Release'
needs: bump-version
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '24'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run build
run: yarn build
- uses: johnyherangi/create-release-notes@main
id: create-release-notes
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Get Last PR Title and Description
id: get-pr-info
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_DATA=$(gh api graphql -f query='
query {
repository(owner: "${{ github.repository_owner }}", name: "${{ github.event.repository.name }}") {
commit: object(expression: "${{ github.sha }}") {
... on Commit {
associatedPullRequests(first: 1) {
edges {
node {
title
body
}
}
}
}
}
}
}
')
PR_TITLE=$(echo "$PR_DATA" | jq -r '.data.repository.commit.associatedPullRequests.edges[0].node.title')
PR_BODY=$(echo "$PR_DATA" | jq -r '.data.repository.commit.associatedPullRequests.edges[0].node.body')
echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT
echo "pr_body<<EOF" >> $GITHUB_OUTPUT
echo "$PR_BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- uses: ncipollo/release-action@v1
with:
makeLatest: true
artifacts: 'dist/**'
generateReleaseNotes: true
tag: ${{ needs.bump-version.outputs.newTag }}
body: |
${{ steps.get-pr-info.outputs.pr_body }}
---
${{ steps.create-release-notes.outputs.release-notes }}
name: '${{ needs.bump-version.outputs.newTag }} - ${{ steps.get-pr-info.outputs.pr_title }}'
update-main:
name: 'Update main branch with release changes'
needs: bump-version
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.BUILD_APP_ID }}
private-key: ${{ secrets.BUILD_PRIVATE_KEY }}
- name: 'Checkout source code'
uses: 'actions/checkout@v2'
with:
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 0
ref: main
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Merge release into main
run: |
git fetch origin release
git merge origin/release
git push origin main