-
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (168 loc) · 6.63 KB
/
craft-release.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
name: Create Release
env:
DOCKER_IMAGE: wyrihaximusgithubactions/supported-php-versions
MILESTONE: ${{ github.event.milestone.title }}
on:
milestone:
types:
- closed
jobs:
wait-for-status-checks:
name: Wait for status checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sleep 13
- name: 'Wait for status checks'
id: waitforstatuschecks
uses: "WyriHaximus/github-action-wait-for-status@master"
with:
ignoreActions: "Wait for status checks"
checkInterval: 5
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- id: generate-version-strategy
if: steps.waitforstatuschecks.outputs.status != 'success'
name: Fail
run: exit 1
generate-version-strategy:
name: Generate Version Strategy
needs:
- wait-for-status-checks
runs-on: ubuntu-latest
outputs:
docker_versions: ${{ steps.generate-version-strategy.outputs.docker_versions }}
tag_versions: ${{ steps.generate-version-strategy.outputs.tag_versions }}
steps:
- uses: actions/checkout@v4
- uses: WyriHaximus/github-action-break-up-semver@v1
id: breakupsemver
with:
version: ${{ env.MILESTONE }}
- id: generate-version-strategy
name: Generate Versions
env:
MAJOR: ${{ steps.breakupsemver.outputs.v_major }}
MAJOR_MINOR: ${{ steps.breakupsemver.outputs.v_major_minor }}
MAJOR_MINOR_PATCH: ${{ steps.breakupsemver.outputs.v_major_minor_patch }}
run: |
echo "::set-output name=docker_versions::[\"${MAJOR}\",\"${MAJOR_MINOR}\",\"${MAJOR_MINOR_PATCH}\"]"
git tag > tag.list
cat tag.list
printf "::set-output name=tag_versions::%s" $(jq --raw-input --slurp 'split("\n")' tag.list -c | php -r "echo json_encode(array_values(array_diff_assoc(json_decode('[\"${MAJOR}\",\"${MAJOR_MINOR}\",\"${MAJOR_MINOR_PATCH}\"]'), json_decode(stream_get_contents(STDIN)))));")
generate-changelog:
name: Generate Changelog
needs:
- generate-version-strategy
runs-on: ubuntu-latest
outputs:
changelog: ${{ steps.changelog.outputs.changelog }}
steps:
- name: Generate changelog
uses: WyriHaximus/github-action-jwage-changelog-generator@v1
id: changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
milestone: ${{ env.MILESTONE }}
- name: Show changelog
run: echo "${CHANGELOG}"
env:
CHANGELOG: ${{ steps.changelog.outputs.changelog }}
tag-docker-image:
name: Tag Docker image for version ${{ matrix.version }}
needs:
- generate-version-strategy
strategy:
matrix:
version: ${{ fromJson(needs.generate-version-strategy.outputs.docker_versions) }}
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
run: |
echo "${{ secrets.HUB_PASSCODE }}" | \
docker login \
--username "${{ secrets.HUB_USERNAME }}" \
--password-stdin
- name: Pull source image
run: docker pull "${DOCKER_IMAGE}:sha-${GITHUB_SHA}"
- name: Retag images for release
run: docker tag "${DOCKER_IMAGE}:sha-${GITHUB_SHA}" "${DOCKER_IMAGE}:${{ matrix.version }}"
- run: docker images
- name: Push release images to Docker Hub
run: docker push "${DOCKER_IMAGE}:${{ matrix.version }}"
create-release:
name: Create Release
needs:
- generate-version-strategy
- tag-docker-image
- generate-changelog
strategy:
matrix:
version: ${{ fromJson(needs.generate-version-strategy.outputs.tag_versions) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create release/${{ matrix.version }} branch
run: git checkout -b release/${{ matrix.version }} ${GITHUB_SHA}
- run: sed -i 's/master/${{ matrix.version }}/g' Dockerfile
- run: cat Dockerfile
- run: git add Dockerfile
- run: git status
- run: echo -e "${CHANGELOG}" > release-${{ matrix.version }}-changelog.md
env:
CHANGELOG: ${{ needs.generate-changelog.outputs.changelog }}
- run: |
echo -e "${MILESTONE_DESCRIPTION}\r\n\r\n${CHANGELOG}" > release-${{ matrix.version }}-release-message.md
cat release-${{ matrix.version }}-release-message.md
release_message=$(cat release-${{ matrix.version }}-release-message.md)
release_message="${release_message//'%'/'%25'}"
release_message="${release_message//$'\n'/'%0A'}"
release_message="${release_message//$'\r'/'%0D'}"
echo "::set-output name=release_message::$release_message"
id: releasemessage
env:
MILESTONE_DESCRIPTION: ${{ github.event.milestone.description }}
CHANGELOG: ${{ needs.generate-changelog.outputs.changelog }}
- run: cat release-${{ matrix.version }}-changelog.md
- name: Set git commit user
run: |
git config user.name '${{ github.actor }}'
git config user.email '${{ github.actor }}@users.noreply.github.com'
- run: git commit -F release-${{ matrix.version }}-changelog.md
- run: git tag -F release-${{ matrix.version }}-changelog.md ${{ matrix.version }}
- name: Push changes
uses: ad-m/github-push-action@v0.6.0
with:
tags: true
branch: release/${{ matrix.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create Reference Release with Changelog
if: ${{ matrix.version == env.MILESTONE }}
uses: fleskesvor/create-release@feature/support-target-commitish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.version }}
release_name: ${{ matrix.version }}
body: ${{ steps.releasemessage.outputs.release_message }}
draft: false
prerelease: false
commitish: release/${{ matrix.version }}
- name: Create Release with Changelog
if: ${{ matrix.version != env.MILESTONE }}
uses: fleskesvor/create-release@feature/support-target-commitish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.version }}
release_name: ${{ matrix.version }}
body: Reference tag to ${{ env.MILESTONE }}
draft: false
prerelease: false
commitish: release/${{ matrix.version }}
- name: Delete release/${{ matrix.version }} branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{github.token}}
branches: release/${{ matrix.version }}