Skip to content

Commit 96963ef

Browse files
authored
Feature release workflow (#41)
* Add release workflows * Fix generate_report
1 parent 677e57c commit 96963ef

File tree

5 files changed

+186
-5
lines changed

5 files changed

+186
-5
lines changed
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: dispatch_release
2+
# Create a new release of the github-actions module
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
feature_branch:
9+
type: string
10+
required: false
11+
description: 'Name of the feature branch, if empty, use the current branch'
12+
default: ''
13+
major:
14+
type: number
15+
required: true
16+
description: 'Major version number (X.?.?)'
17+
minor:
18+
type: number
19+
required: true
20+
description: 'Minor version number (?.X.?)'
21+
patch:
22+
type: number
23+
required: true
24+
description: 'Patch version number (?.?.X)'
25+
reviewer:
26+
type: choice
27+
required: true
28+
description: 'who should review the PR'
29+
options:
30+
- joernott
31+
- snehasreeramini
32+
jobs:
33+
prepare_release:
34+
runs-on: 'ubuntu-latest'
35+
steps:
36+
- name: 'Get branch'
37+
id: branch
38+
run: |
39+
# Get branch
40+
BRANCH='${{ inputs.feature_branch }}'
41+
if [ -z "${BRANCH}" ]; then
42+
BRANCH="${GITHUB_REF}"
43+
fi
44+
echo "branch=${BRANCH}" >>"${GITHUB_OUTPUTS}"
45+
46+
- name: 'Checkout testplan defaults'
47+
uses: actions/checkout@v4
48+
with:
49+
repository: 'OXID-eSales/github-actions'
50+
ref: '${{ steps.branch.outputs.branch }}'
51+
path: 'github-actions'
52+
53+
- name: Validate version
54+
run: |
55+
# Validate version
56+
cd github-actions
57+
CHECK=$(git tag --list|grep "v${{inputs.major}}.${{inputs.minor}}.${{inputs.patch}}"||true)
58+
if [ -n "${CHECK}" ]; then
59+
cat <<EOF
60+
*******************************************************************
61+
* Tag v${{inputs.major}}.${{inputs.minor}}.${{inputs.patch}} already exists. Aborting
62+
*******************************************************************
63+
EOF
64+
exit 1
65+
fi
66+
67+
- name: 'Create release'
68+
run: |
69+
# Merge main branch
70+
cd github-actions
71+
git checkout main
72+
git pull
73+
git checkout '${{ steps.branch.outputs.branch }}'
74+
git merge main
75+
STATUS=$(git status -s)
76+
if [ -n "${STATUS}" ]; then
77+
git add --all
78+
git commit -m "Merge main branch"
79+
fi
80+
git checkout -b "release/${{inputs.major}}.${{inputs.minor}}.${{inputs.patch}}"
81+
FILES=$(find . -iname '*.yml')
82+
for FILE in ${FILES}; do
83+
sed -i "${FILE}" \
84+
-E 's|OXID-eSales/github-actions/(.*)@v(.*)|OXID-eSales/github-actions/\1@v${{ inputs.major}}|g'
85+
done
86+
STATUS=$(git status -s)
87+
if [ -n "${STATUS}" ]; then
88+
git add --all
89+
git commit -m "Bump major version to ${{inputs.major}}"
90+
fi
91+
92+
- name: Create branch and Pull Request
93+
uses: peter-evans/create-pull-request@v5
94+
with:
95+
path: 'github-actions'
96+
base: 'main'
97+
branch: 'release/${{inputs.major}}.${{inputs.minor}}.${{inputs.patch}}'
98+
assignees: '${{inputs.reviewer}}'
99+
reviewers: '${{inputs.reviewer}}'
100+
title: 'Update github-actions to ${{inputs.major}}.${{inputs.minor}}.${{inputs.patch}}'

.github/workflows/merge-release.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: merge_release
2+
# Create a new release of the github-actions module
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
pull_request:
7+
types:
8+
- closed
9+
branches:
10+
- main
11+
12+
jobs:
13+
if_merged:
14+
if: github.event.pull_request.merged
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Get data'
18+
id: data
19+
env:
20+
TITLE: ${{github.event.pull_request.title}}
21+
run: |
22+
# Get data
23+
if [[ "${TITLE}" != "Update github-actions to "* ]]; then
24+
echo "skip=true" | tee -a "${GITHUB_OUTPUTS}"
25+
fi
26+
# shellcheck disable=SC2001
27+
VERSION=$(echo "${TITLE}"|sed -e 's|.* ||')
28+
# shellcheck disable=SC2016
29+
MAJOR=${echo "${VERSION}"|awk -F '.' '{print $1}'}
30+
# shellcheck disable=SC2016
31+
MINOR=${echo "${VERSION}"|awk -F '.' '{print $2}'}
32+
# shellcheck disable=SC2016
33+
PATCH=${echo "${VERSION}"|awk -F '.' '{print $3}'}
34+
echo "version=${VERSION}" | tee -a "${GITHUB_OUTPUTS}"
35+
echo "major=${MAJOR}" | tee -a "${GITHUB_OUTPUTS}"
36+
echo "minor=${MINOR}" | tee -a "${GITHUB_OUTPUTS}"
37+
echo "patch=${PATCH}" | tee -a "${GITHUB_OUTPUTS}"
38+
39+
- name: 'Checkout testplan defaults'
40+
if: ${{ steps.data.outputs.skip != 'true' }}
41+
uses: actions/checkout@v4
42+
with:
43+
repository: 'OXID-eSales/github-actions'
44+
ref: 'main'
45+
path: 'github-actions'
46+
47+
- name: 'Tagging'
48+
if: ${{ steps.data.outputs.skip != 'true' }}
49+
run: |
50+
# Tagging
51+
VERSION="${{steps.data.outputs.major}}.${{steps.data.outputs.minor}}.${{steps.data.outputs.patch}}"
52+
git tag -a "v${VERSION}" -m "Release v${VERSION}"
53+
CHECK=$(git tag --list|grep "v${{steps.data.outputs.major}}.${{steps.data.outputs.minor}}"||true)
54+
if [ -n "${CHECK}" ]; then
55+
echo "Moving tag v${{steps.data.outputs.major}}.${{steps.data.outputs.minor}}"
56+
git push --delete origin v${{steps.data.outputs.major}}.${{steps.data.outputs.minor}}
57+
git tag -d v${{steps.data.outputs.major}}.${{steps.data.outputs.minor}}
58+
fi
59+
git tag -a v${{steps.data.outputs.major}}.${{steps.data.outputs.minor}} -m "Release v${VERSION}"
60+
CHECK=$(git tag --list|grep "v${{steps.data.outputs.major}}"||true)
61+
if [ -n "${CHECK}" ]; then
62+
echo "Moving tag v${{steps.data.outputs.major}}"
63+
git push --delete origin v${{steps.data.outputs.major}}
64+
git tag -d v${{steps.data.outputs.major}}
65+
fi
66+
git tag -a v${{steps.data.outputs.major}} -m "Release v${VERSION}"
67+
git push --tags
68+
69+
- uses: ncipollo/release-action@v1
70+
if: ${{ steps.data.outputs.skip != 'true' }}
71+
with:
72+
token: ${{github.token}}
73+
tag: 'v${{steps.data.outputs.major}}.${{steps.data.outputs.minor}}.${{steps.data.outputs.patch}}'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

generate_report/action.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ runs:
144144
shell: bash
145145
run: |
146146
# generate_report: Generate cache list
147-
echo "cache_objects<<EOF" | tee -a "${GITHUB_OUTPUTS}"
148-
cat caches/*.txt | tee -a "${GITHUB_OUTPUTS}"
149-
echo "EOF" | tee -a "${GITHUB_OUTPUTS}"
147+
FILES=$(find caches -iname '*.txt')
148+
if [ -n "${FILES}" ]; then
149+
echo "cache_objects<<EOF" | tee -a "${GITHUB_OUTPUTS}"
150+
cat caches/*.txt | tee -a "${GITHUB_OUTPUTS}"
151+
echo "EOF" | tee -a "${GITHUB_OUTPUTS}"
152+
else
153+
echo "cache_objects=" | tee -a "${GITHUB_OUTPUTS}"
154+
fi
150155
151156
- name: Upload Artifacts
152-
# yamllint enable rule:line-length
153-
154157
if: always()
155158
uses: actions/upload-artifact@v3
156159
with:

tests/github_actions/defaults/defaults.yml

+4
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ install_module:
332332
# Path to install the module under dev-packages, should be the same as module_ids
333333
path: &module_path ''
334334

335+
# What modules should be activated
336+
activate: *module_ids
337+
338+
335339
# Run custom script outside the container'
336340
custom_script: ''
337341

0 commit comments

Comments
 (0)