Skip to content

Create New Release

Create New Release #4

Workflow file for this run

name: "Create New Release"
permissions:
contents: write
pull-requests: write
env:
Timezone: "Etc/UTC"
on:
workflow_dispatch:
inputs:
increment:
description: 'Semver increment. Leave empty for automatic detection'
required: false
type: choice
default: 'AUTO'
options:
- 'AUTO'
- 'PATCH'
- 'MINOR'
- 'MAJOR'
publish-gh-pages:
description: 'Should this new version be published to GitHub-Pages?'
required: false
type: boolean
default: true
jobs:
lint:
uses: RonMcKay/gradient_metrics/.github/workflows/lint.yml@main
with:
ref: "${{ github.sha }}"
test:
uses: RonMcKay/gradient_metrics/.github/workflows/test.yml@main
with:
ref: "${{ github.sha }}"
create-release:
needs: [lint, test]
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref_name, 'release/') || github.ref_name == 'main' }}
outputs:
new_version: ${{ steps.bump_version.outputs.version }}
steps:
- name: "Checkout"
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
with:
python-version-file: '.python-version'
- name: Install commitizen
run: python3 -m pip install "commitizen~=2.39.1"
- name: Setup Git
run: |
git config user.name 'Philipp Oberdiek'
git config user.email 'git@oberdiek.net'
git config push.autoSetupRemote true
# Get current date
- name: Get current date
id: today
run: echo "date=$(TZ=${{ env.Timezone }} date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
# Get current version
- name: Get old version
id: old_version
run: echo "version=$(cz version --project)" >> $GITHUB_OUTPUT
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v3
with:
configuration: ".github/changelog-config.json"
owner: "RonMcKay"
repo: "gradient_metrics"
toTag: ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
# Save changelog to file and remove trailing newlines
- name: "Save changelog changes to file"
run: echo '${{ steps.build_changelog.outputs.changelog }}' | sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' > tmp-changelog.md
# Detect increment
- name: Detect increment
if: inputs.increment == 'AUTO'
id: detect_increment
run: echo "increment=$(.github/detect-increment.sh tmp-changelog.md)" >> $GITHUB_OUTPUT
- name: Register correct increment
id: set_increment
run: |
if [ "${{ inputs.increment }}" == "AUTO" ]; then
echo "increment=${{ steps.detect_increment.outputs.increment }}" >> $GITHUB_OUTPUT
else
echo "increment=${{ inputs.increment }}" >> $GITHUB_OUTPUT
fi
# Bump version and save version information to output
- name: Bump version
id: bump_version
run: |
cz bump --files --yes --increment ${{ steps.set_increment.outputs.increment }}
echo "version=$(cz version --project)" >> $GITHUB_OUTPUT
# Insert changes into CHANGELOG.md
- name: "Add changes to CHANGELOG.md"
run: sed -i -E "0,/^## [0-9]+.*$/s/^## [0-9]+.*$/## ${{ steps.bump_version.outputs.version }} (${{ steps.today.outputs.date }})\n\n$(<tmp-changelog.md sed -e 's/[\&/]/\\&/g' -e 's/$/\\n/' | tr -d '\n')\n&/" CHANGELOG.md
# Create new branch for release
- name: Create release branch
if: ${{ !startsWith(github.ref_name, 'release/') }}
id: release_branch
run: |
git checkout -b "release/v${{ steps.bump_version.outputs.version }}"
git push origin "release/v${{ steps.bump_version.outputs.version }}"
echo "name=release/v${{ steps.bump_version.outputs.version }}" >> $GITHUB_OUTPUT
# Commit changes and push with new tag
- name: "Commit version bump and changelog update and push"
run: |
git add -u
git commit -m "release v${{ steps.bump_version.outputs.version }}"
git tag -a -m "v${{ steps.bump_version.outputs.version }}" v${{ steps.bump_version.outputs.version }}
git push origin --follow-tags
- name: "Create release from new tag"
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.bump_version.outputs.version }}
body_path: ${{ github.workspace }}/tmp-changelog.md
token: ${{ secrets.GITHUB_TOKEN }}
# Only create pull request if the release branch was not already existing
# as in the case of a hotfix e.g.
- name: "Create Pull Request into main"
if: ${{ !startsWith(github.ref_name, 'release/') }}
run: GH_TOKEN=${{ github.token }} gh pr create --assignee "RonMcKay" --base "main" --head "${{ steps.release_branch.outputs.name }}" --title "Changelog v${{ steps.bump_version.outputs.version }}" --body-file "tmp-changelog.md"
publish-to-testpypi:
needs: create-release
uses: RonMcKay/gradient_metrics/.github/workflows/publish-to-testpypi.yml@main
with:
ref: "v${{ needs.create-release.outputs.new_version }}"
secrets: inherit
publish-to-pypi:
needs: create-release
uses: RonMcKay/gradient_metrics/.github/workflows/publish-to-pypi.yml@main
with:
ref: "v${{ needs.create-release.outputs.new_version }}"
secrets: inherit
publish-to-gh-pages:
if: ${{ inputs.publish-gh-pages }}
uses: RonMcKay/gradient_metrics/.github/workflows/gh-pages.yml@main
with:
ref: "${{ github.sha }}"