-
Notifications
You must be signed in to change notification settings - Fork 26
196 lines (180 loc) · 8.54 KB
/
build_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
# ------------------------------------------------------------------------------------------
# This is a workflow to release this project as a zipped installable artifact.
# Release version numbering and release notes generation is following standards defined by:
#
# https://semver.org
# https://keepachangelog.com
# https://common-changelog.org
#
# Note: Since DokuWiki is using version numbering in format YYYY-MM-DD we use this numbering
# format rather than a dotted numbering scheme.
# The git tag names have to use a 'v' as prefix to the DokuWiki version number.
#
# ------------------------------------------------------------------------------------------
name: Build a release
on:
# Triggers the workflow on push of a tag filtering the tag to meet
# semantic version numbering according to https://semver.org
# Here we use the DokuWiki conform version number pattern.
push:
tags:
['v[0-9]+-[0-9]+-[0-9]+']
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
# Ensure that we run on tag references only
validate_github_reference:
name: Validate the tag reference
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Validate tag
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
steps:
- run: |
echo "The selected git ref=${{ github.ref }} is NOT a valid release tag. Please select a valid release TAG as reference."
exit 1
# Create a release
release:
name: Release
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Set job wide environment
env:
APP_NAME: dokuwiki-plugin-gitbacked
APP_INFO_FILE: plugin.info.txt
APP_INFO_FILE_VERSION_KEY: date
BUILD_DIR: build
ZIP_EXCLUSIONS: '*.git* .editorconfig /*.github/* /*build/* RELEASE_HEAD.md'
steps:
# Log use case if triggered manually
- name: Log use case if triggered manually
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "Workflow has been triggered manually"
# Log use case if triggered by push
- name: Log use case if triggered by push
if: ${{ github.event_name == 'push' }}
run: |
echo "Workflow has been triggered by push to ${{ github.ref }}"
# Check out this repo
- name: Checkout
uses: actions/checkout@v3
# Set version tags as global environment properties
- name: Prepare Version Tags
run: |
#echo "MAJOR_VERSION=$(echo ${GITHUB_REF/refs\/tags\//} | awk -F'-' '{print $1}')" >> $GITHUB_ENV
#echo "MINOR_VERSION=$(echo ${GITHUB_REF/refs\/tags\//} | awk -F'-' '{print $1"-"$2}')" >> $GITHUB_ENV
#echo "FULL_VERSION=$(echo ${GITHUB_REF/refs\/tags\//} | awk -F'-' '{print $1"-"$2"-"$3}')" >> $GITHUB_ENV
echo "VERSION_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
echo "APP_INFO_VERSION=$(sed -n -E 's/^${{ env.APP_INFO_FILE_VERSION_KEY }}[ \t]+([0-9-]+).*/\1/p' ${{ env.APP_INFO_FILE }})" >> $GITHUB_ENV
# Validate app info version and set release name
- name: Validate app info version and set release name
run: |
if [ "${{ env.RELEASE_VERSION }}" != "${{ env.APP_INFO_VERSION }}" ]; then
echo "Mismatch of release version=${{ env.RELEASE_VERSION }} and application info version=${{ env.APP_INFO_VERSION }}!" >&2
echo "Please review the value for key=${{ env.APP_INFO_FILE_VERSION_KEY }} in file ${{ env.APP_INFO_FILE }}."
exit 1
fi
echo "RELEASE_NAME=Release ${{ env.APP_INFO_VERSION }}" >> $GITHUB_ENV
- name: Validate CHANGELOG.md for this release version
# explanation of sed command:
# 1. select lines between SED_VERSION_BEGIN_PATTERN and SED_VERSION_END_PATTERN
# 2. invert this selection
# 3. delete it
# => only selection is remaining in stream
run: |
SED_VERSION_BEGIN_PATTERN="/^## \\[${{ env.RELEASE_VERSION }}\\]/"
SED_VERSION_END_PATTERN="/^## /"
echo "Pattern used for sed: ${SED_VERSION_BEGIN_PATTERN},${SED_VERSION_END_PATTERN} ! d"
#
# Extract the release notes for this RELEASE_VERSION including the line of the previous version:
#
RELEASE_NOTES_WITH_PREV_VERSION=$(sed -e "${SED_VERSION_BEGIN_PATTERN},${SED_VERSION_END_PATTERN} ! d" CHANGELOG.md)
echo ">>>>>> RELEASE_NOTES_WITH_PREV_VERSION - BEGIN >>>>>>"
echo "${RELEASE_NOTES_WITH_PREV_VERSION}"
echo "<<<<<< RELEASE_NOTES_WITH_PREV_VERSION - END <<<<<<"
#
# Format the release notes:
#
# 1. Remove last 2 lines: head -n 2
# 2. Remove any empty line from the end: sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
# (s. http://sed.sourceforge.net/sed1line.txt for reference)
#
#RELEASE_VERSION_NOTES=$(echo "$RELEASE_NOTES_WITH_PREV_VERSION" | head -n -2 | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}')
#echo "${RELEASE_VERSION_NOTES}" >> RELEASE.md
#printf "\n" >> RELEASE.md
#
# Extract previous release version:
#
# 1. Cut the last line only: tail -1
# 2. Get the version from the enclosing [] brackets: awk -F "[][]" '{ print $2 }'
#
PREV_RELEASE_VERSION=$(echo "$RELEASE_NOTES_WITH_PREV_VERSION" | tail -1 | awk -F "[][]" '{ print $2 }')
if [ -z "$PREV_RELEASE_VERSION" ]; then
EXPECTED_COMPARE_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ env.RELEASE_VERSION }}"
else
EXPECTED_COMPARE_URL="${{ github.server_url }}/${{ github.repository }}/compare/v${PREV_RELEASE_VERSION}..v${{ env.RELEASE_VERSION }}"
fi
# Validate CHANGELOG.md content
IS_OK="true"
if ! grep -q "^## \\[${{ env.RELEASE_VERSION }}\\]" CHANGELOG.md; then
IS_OK="false"
echo "ERROR: CHANGELOG.md does not contain an entry for this release version of format: ## [${{ env.RELEASE_VERSION }}]"
fi
if ! grep -q "^\\[${{ env.RELEASE_VERSION }}\\]: ${EXPECTED_COMPARE_URL}" CHANGELOG.md; then
IS_OK="false"
echo "ERROR: CHANGELOG.md does not contain a line with a compare link of format: [${{ env.RELEASE_VERSION }}]: ${EXPECTED_COMPARE_URL}"
fi
if [ "$IS_OK" != "true" ]; then
echo "Please review CHANGELOG.md and update it for the content expected."
exit 1
fi
# Prepare release notes and build directory
- name: Prepare release notes and build directory
run: |
mkdir ${{ env.BUILD_DIR }}
#cp ./README.md ${{ env.BUILD_DIR }}/README.md
touch ${{ env.BUILD_DIR }}/README.md
cp ./CHANGELOG.md ${{ env.BUILD_DIR }}/CHANGELOG.md
cp ./.github/workflows/resources/RELEASE_HEAD.md ${{ env.BUILD_DIR }}/RELEASE_HEAD.md
# Format the filename of this release
- name: Format release filename
id: format_release_filename
run: |
echo "FILE_NAME=${{ env.APP_NAME }}-${{ env.APP_INFO_VERSION }}.zip" >> $GITHUB_OUTPUT
# Create archive file
- name: Build release archive
uses: GHCICD/zip-release@master
with:
type: 'zip'
filename: ${{ env.BUILD_DIR }}/${{ steps.format_release_filename.outputs.FILE_NAME }}
exclusions: ${{ env.ZIP_EXCLUSIONS }}
# Create release notes by release-notes-from-changelog
- name: Create release notes by GHCICD/release-notes-from-changelog@v1
uses: GHCICD/release-notes-from-changelog@v1
with:
version: ${{ env.RELEASE_VERSION }}
working-directory: ${{ env.BUILD_DIR }}
- name: Log RELEASE.md
run: |
echo ">>>>> build/RELEASE.md:"
cat ${{ env.BUILD_DIR }}/RELEASE.md
echo "<<<<<"
# echo ">>>>> build/CHANGELOG.md:"
# cat ${{ env.BUILD_DIR }}/CHANGELOG.md
# echo "<<<<<"
# Create release with info from CHANGELOG.md
- name: Create GitHub release by ncipollo/release-action@v1
id: create_release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ env.RELEASE_NAME }}
tag: ${{ env.VERSION_TAG }}
bodyFile: ${{ env.BUILD_DIR }}/RELEASE.md
artifacts: ${{ env.BUILD_DIR }}/${{ steps.format_release_filename.outputs.FILE_NAME }}
artifactContentType: application/zip
#
# EOF
#