-
-
Notifications
You must be signed in to change notification settings - Fork 389
235 lines (233 loc) · 9.16 KB
/
readme-release.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Update README and create release
on:
push:
branches:
- master
create:
tags:
- "*"
repository_dispatch:
types:
- readme-release
workflow_dispatch:
jobs:
readme-release:
runs-on: ubuntu-latest
env:
VERSIONTAG_THIS: ""
steps:
-
name: Checkout
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/master')
|| (github.event_name == 'create' && github.event.ref_type == 'tag')
|| github.event_name == 'repository_dispatch'
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
-
name: Update README
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/master')
|| github.event_name == 'repository_dispatch'
run: |
./scripts/update-readme
if ! git ls-files -m | grep -qE '^README\.md$'; then
echo 'README.md has not been changed'
else
echo 'README.md has been updated'
git config user.name 'Michele Locati'
git config user.email '[email protected]'
git add README.md
git commit -m '[skip ci] Automatically update README.md'
git push
fi
-
name: Look for the recent version tags
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/master')
|| (github.event_name == 'create' && github.event.ref_type == 'tag')
|| github.event_name == 'repository_dispatch'
run: |
TAGS="$(git tag --list --sort=-version:refname)"
VERSIONTAG_LAST=
VERSIONTAG_PENULTIMATE=
for TAG in $(git tag --list --sort=-version:refname); do
if printf '%s' "$TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
if test -z "$VERSIONTAG_LAST"; then
VERSIONTAG_LAST="$TAG"
else
VERSIONTAG_PENULTIMATE="$TAG"
break
fi
fi
done
if test -z "$VERSIONTAG_LAST"; then
printf 'Most recent version tag: <none>\n'
else
printf 'Most recent version tag: %s\n' "$VERSIONTAG_LAST"
fi
printf 'VERSIONTAG_LAST=%s\n' "$VERSIONTAG_LAST" >> "$GITHUB_ENV"
printf 'VERSIONTAG_PENULTIMATE=%s\n' "$VERSIONTAG_PENULTIMATE" >> "$GITHUB_ENV"
-
name: Check if we need to create a version tag after a push
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
VERSIONTAG_THIS=
if test -z "$VERSIONTAG_LAST"; then
printf 'We need to create the first version tag\n'
VERSIONTAG_THIS=1.0.0
elif test "$(git rev-parse HEAD)" = "$(git rev-list -n 1 "refs/tags/$VERSIONTAG_LAST")"; then
printf 'Another action should already take care of creating the release\n'
else
CREATE_TAG=n
for CHANGED_FILE in $(git diff --name-only "refs/tags/$VERSIONTAG_LAST" HEAD); do
case "$CHANGED_FILE" in
install-php-extensions | Dockerfile)
CREATE_TAG=y
;;
esac
done
if test "$CREATE_TAG" = 'y'; then
VERSIONTAG_THIS="${VERSIONTAG_LAST%.*}.$((${VERSIONTAG_LAST##*.}+1))"
printf 'We need to create new version tag %s since relevant files changed\n' "$VERSIONTAG_THIS"
else
printf 'We do not need to create a new version tag since no relevant files changed\n'
fi
fi
printf 'VERSIONTAG_THIS=%s\n' "$VERSIONTAG_THIS" >> "$GITHUB_ENV"
printf 'VERSIONTAG_PREVIOUS=%s\n' "$VERSIONTAG_LAST" >> "$GITHUB_ENV"
-
name: Sleep for a while before creating a tag
if: env.VERSIONTAG_THIS != ''
uses: juliangruber/sleep-action@v1
with:
time: 30s
-
name: Create version tag after a push in the local repository
if: env.VERSIONTAG_THIS != ''
run: |
git tag -- "$VERSIONTAG_THIS"
printf 'VERSIONTAG_THIS_SHA=%s\n' "$(git rev-parse HEAD)" >> "$GITHUB_ENV"
-
name: Create version tag after a push in the remote repository
if: env.VERSIONTAG_THIS != ''
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${process.env.VERSIONTAG_THIS}`,
sha: process.env.VERSIONTAG_THIS_SHA
})
-
name: Check format of received tag
if: github.event_name == 'create' && github.event.ref_type == 'tag'
run: |
VERSIONTAG_THIS="${GITHUB_REF#refs/tags/}"
if test "$VERSIONTAG_THIS" = "$VERSIONTAG_LAST"; then
if printf '%s' "$VERSIONTAG_THIS" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
printf 'Tag %s is version-like\n' "$VERSIONTAG_THIS"
else
printf 'Tag %s is not version-like\n' "$VERSIONTAG_THIS"
VERSIONTAG_THIS=
fi
else
printf 'Last created tag %s is not %\n' "$VERSIONTAG_THIS" "$VERSIONTAG_LAST"
VERSIONTAG_THIS=
fi
printf 'VERSIONTAG_THIS=%s\n' "$VERSIONTAG_THIS" >> "$GITHUB_ENV"
printf 'VERSIONTAG_PREVIOUS=%s\n' "$VERSIONTAG_PENULTIMATE" >> "$GITHUB_ENV"
-
name: Extract release notes
if: env.VERSIONTAG_THIS != ''
run: |
printf 'Generating release notes for tag %s\n' "$VERSIONTAG_THIS"
if test -z "$VERSIONTAG_PREVIOUS"; then
echo 'No previous tag found'
RELEASE_NOTES='First version'
else
printf 'Generating release notes for commits between %s and %s\n' "$VERSIONTAG_PREVIOUS" "$VERSIONTAG_THIS"
if ! RELEASE_NOTES="$(git log --format='- %s' --no-merges --reverse "refs/tags/$VERSIONTAG_PREVIOUS...refs/tags/$VERSIONTAG_THIS" -- ./install-php-extensions ./Dockerfile | grep -vE '^- \[minor\]')"; then
RELEASE_NOTES=
fi
fi
printf 'Release notes:\n%s\n' "$RELEASE_NOTES"
printf 'RELEASE_NAME=v%s\n' "$VERSIONTAG_THIS" >> "$GITHUB_ENV"
printf 'RELEASE_NOTES<<EOF\n%s\nEOF\n' "$RELEASE_NOTES" >> "$GITHUB_ENV"
-
name: Set script version
if: env.VERSIONTAG_THIS != ''
run: sed -i -E "s/^(IPE_VERSION=)master$/\1$VERSIONTAG_THIS/" install-php-extensions
-
name: Login to Docker Hub
if: env.VERSIONTAG_THIS != ''
uses: docker/login-action@v3
with:
username: mlocati
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
if: env.VERSIONTAG_THIS != ''
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set up docker buildx
if: env.VERSIONTAG_THIS != ''
uses: docker/setup-buildx-action@v2
with:
install: true
-
name: Define versions
if: env.VERSIONTAG_THIS != ''
id: define-versions
run: |
printf 'mayor-minor-patch=%s\n' "$VERSIONTAG_THIS" >>"$GITHUB_OUTPUT"
printf 'mayor-minor=%s\n' "${VERSIONTAG_THIS%.*}" >>"$GITHUB_OUTPUT"
printf 'mayor=%s\n' "${VERSIONTAG_THIS%%.*}" >>"$GITHUB_OUTPUT"
-
name: Build and push docker image
if: env.VERSIONTAG_THIS != ''
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
mlocati/php-extension-installer:${{ steps.define-versions.outputs.mayor-minor-patch }}
ghcr.io/mlocati/php-extension-installer:${{ steps.define-versions.outputs.mayor-minor-patch }}
mlocati/php-extension-installer:${{ steps.define-versions.outputs.mayor-minor }}
ghcr.io/mlocati/php-extension-installer:${{ steps.define-versions.outputs.mayor-minor }}
mlocati/php-extension-installer:${{ steps.define-versions.outputs.mayor }}
ghcr.io/mlocati/php-extension-installer:${{ steps.define-versions.outputs.mayor }}
mlocati/php-extension-installer:latest
ghcr.io/mlocati/php-extension-installer:latest
# Build for all platforms also supported by php images (https://hub.docker.com/_/php/tags)
platforms: |
linux/386
linux/amd64
linux/arm/v5
linux/arm/v7
linux/arm64/v8
linux/mips64le
linux/ppc64le
linux/s390x
-
name: Create release
if: env.VERSIONTAG_THIS != ''
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSIONTAG_THIS }}
name: ${{ env.RELEASE_NAME }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false
generate_release_notes: false
fail_on_unmatched_files: true
files: |
install-php-extensions