Skip to content

Commit

Permalink
PLUG-155: Verify version and autorelease in pipelines (#34)
Browse files Browse the repository at this point in the history
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
artyom-jaksov-tl authored Oct 31, 2024
1 parent 2a94c94 commit de67360
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/check-version.yml
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"* ]]
69 changes: 69 additions & 0 deletions .github/workflows/create-tag.yml
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
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<default>
<payment>
<truelayer>
<version>2.3.0</version>
<version>2.3.1</version>
<model>TrueLayerFacade</model>
<title>TrueLayer</title>
<description>Make a direct payment securely from your bank app - no card needed</description>
Expand Down

0 comments on commit de67360

Please sign in to comment.