diff --git a/.github/workflows/check-version.yml b/.github/workflows/check-version.yml new file mode 100644 index 0000000..0b2aff4 --- /dev/null +++ b/.github/workflows/check-version.yml @@ -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*.' | tail -1 | tr -d '\-[:blank:]\n' | sed -e 's/\(.*\)<\/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*.' | head -1 | tr -d '+[:blank:]\n' | sed -e 's/\(.*\)<\/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"* ]] diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml new file mode 100644 index 0000000..7774baa --- /dev/null +++ b/.github/workflows/create-tag.yml @@ -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 '' | tr -d '\-[:blank:]\n' | sed -e 's/\(.*\)<\/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 "github-actions@users.noreply.github.com" + 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 diff --git a/etc/config.xml b/etc/config.xml index c07d1f5..552f8b3 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -10,7 +10,7 @@ - 2.3.0 + 2.3.1 TrueLayerFacade TrueLayer Make a direct payment securely from your bank app - no card needed