-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLUG-155: Verify version and autorelease in pipelines (#34)
Added a pipeline to verify that the incoming etc/config.xml has a higher version number than the one in main Added a pipeline to automatically create a new tag and release when pushing to main
- Loading branch information
1 parent
2a94c94
commit de67360
Showing
3 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Check config.xml version | ||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
branches: [main] | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
fetch-depth: 0 | ||
|
||
- name: Set OLD_VERSION from etc/config.xml if merge would modify it | ||
run: | | ||
echo "OLD_VERSION=$(git log origin/main..HEAD --cherry -p -- etc/config.xml | grep '\-.\s*.<version>' | tail -1 | tr -d '\-[:blank:]\n' | sed -e 's/<version>\(.*\)<\/version>/\1/')" >> $GITHUB_ENV | ||
- name: Set NEW_VERSION from etc/config.xml if merge would modify it | ||
run: | | ||
echo "NEW_VERSION=$(git log origin/main..HEAD --cherry -p -- etc/config.xml | grep '\+.\s*.<version>' | head -1 | tr -d '+[:blank:]\n' | sed -e 's/<version>\(.*\)<\/version>/\1/')" >> $GITHUB_ENV | ||
- name: Test that versions are not empty | ||
run: | | ||
[[ ! -z $OLD_VERSION ]] && [[ ! -z $NEW_VERSION ]] | ||
- name: Test that versions are different | ||
run: | | ||
[[ $OLD_VERSION != $NEW_VERSION ]] | ||
- name: Test that version string mathches pattern | ||
run: | | ||
[[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]$ ]] | ||
- name: Sort versions | ||
run: | | ||
if [[ $OLD_VERSION =~ ^[0-9]+(\.[0-9]+)+\.[0-9]$ ]]; then | ||
echo "GREATER_VERSION=$(echo -e ${OLD_VERSION}\\n${NEW_VERSION} | sort --version-sort | tail -n1)" >> $GITHUB_ENV | ||
else | ||
echo "GREATER_VERSION=$NEW_VERSION" >> $GITHUB_ENV | ||
fi | ||
- name: Make sure new version is greater | ||
run: | | ||
[[ $GREATER_VERSION == $NEW_VERSION ]] | ||
- name: Ensure changelog is not empty for the new version | ||
run: | | ||
CHANGELOG=$(sed -n "/^## \[v$NEW_VERSION\]/,/^## \[v/p" CHANGELOG.md | sed -e "s/^## \[v.*\$//" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba') | ||
[[ -n $CHANGELOG ]] | ||
[[ $CHANGELOG == *"### Added"* || $CHANGELOG == *"### Changed"* || $CHANGELOG == *"### Fixed"* ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Create Tag | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags-ignore: | ||
- '**' | ||
|
||
jobs: | ||
tag: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: '0' | ||
|
||
- name: Generate Git Tag | ||
id: generate_tag | ||
run: | | ||
NEW_TAG=v$(cat etc/config.xml | grep '<version>' | tr -d '\-[:blank:]\n' | sed -e 's/<version>\(.*\)<\/version>/\1/') | ||
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV | ||
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_OUTPUT | ||
- name: Test that version string mathches pattern | ||
run: | | ||
[[ $NEW_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]$ ]] | ||
- name: Test for tag collision | ||
run: | | ||
TAG_EXISTS=0 | ||
for EXISTING_TAG in `git tag -l`; do | ||
if [[ $EXISTING_TAG == $NEW_TAG || v$EXISTING_TAG == $NEW_TAG ]]; then | ||
TAG_EXISTS=1 | ||
break | ||
fi | ||
done | ||
[[ $TAG_EXISTS == 0 ]] | ||
- name: Ensure changelog is not empty for the new tag | ||
run: | | ||
CHANGELOG=$(sed -n "/^## \[$NEW_TAG\]/,/^## \[v/p" CHANGELOG.md | sed -e "s/^## \[v.*\$//" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba') | ||
[[ -n $CHANGELOG ]] | ||
[[ $CHANGELOG == *"### Added"* || $CHANGELOG == *"### Changed"* || $CHANGELOG == *"### Fixed"* ]] | ||
- name: Push Git Tag | ||
run: | | ||
git config user.name "GitHub Actions" | ||
git config user.email "[email protected]" | ||
git tag $NEW_TAG | ||
git push origin $NEW_TAG | ||
- name: Create changelog diff | ||
run: | | ||
sed -n "/^## \[$NEW_TAG\]/,/^## \[v/p" CHANGELOG.md | sed -e "s/^## \[v.*\$//" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.md | ||
- name: Create release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ steps.generate_tag.outputs.NEW_TAG }} | ||
release_name: ${{ steps.generate_tag.outputs.NEW_TAG }} | ||
body_path: ./release_notes.md | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Delete release_notes file | ||
run: rm release_notes.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters