Skip to content

(Tag): Prepare

(Tag): Prepare #24

Workflow file for this run

name: "(Tag): Prepare"
permissions:
contents: write
pull-requests: write
actions: read
on:
workflow_dispatch:
inputs:
version:
description: 'Version to create the tag for (e.g. 3.6.9) or `next`'
required: true
type: string
default: next
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout branch for release
uses: actions/checkout@v4
- name: Determine version
id: version
run: |
INPUT_VERSION=${{ github.event.inputs.version }}
if [ -z "$INPUT_VERSION" ]; then
echo "::info:: No version input provided, defaulting to 'next'."
INPUT_VERSION="next"
fi
if [ $INPUT_VERSION = "next" ]; then
CURR=$(jq -r .version composer.json)
MAJOR=$(echo $CURR | cut -d. -f1)
MINOR=$(echo $CURR | cut -d. -f2)
PATCH=$(echo $CURR | cut -d. -f3)
NEW_PATCH=$((PATCH+1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
VERSION="$NEW_VERSION"
else
VERSION="${{ github.event.inputs.version }}"
fi
if [ -z "$VERSION" ]; then
echo "::error::Version is empty. Failing job."
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
generate-changelog:
needs: get-version
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: read
models: read
strategy:
matrix:
include:
- target-file: "CHANGELOG.md"
template: "changelog"
- target-file: "src/readme.txt"
template: "readme"
steps:
- name: Checkout changelog-action private repo
uses: actions/checkout@v4
with:
repository: codesnippetspro/changelog-action
token: ${{ secrets.PRIVATE_ACTION_TOKEN }}
path: ./changelog-action
- name: Generate patch for ${{ matrix.target-file }}
id: build
uses: ./changelog-action
with:
repo: ${{ github.repository }}
branch: ${{ github.ref_name }}
tag: ${{ needs.get-version.outputs.version }}
target-file: ${{ matrix.target-file }}
template: ${{ matrix.template }}
git-push:
runs-on: ubuntu-latest
needs: [get-version, generate-changelog]
steps:
- name: Checkout branch for release
uses: actions/checkout@v4
- name: Configure Git
run: |
git config user.name "code-snippets-bot"
git config user.email "[email protected]"
- name: Create and switch to tag branch
run: |
git checkout -b "tag/v${{ needs.get-version.outputs.version }}"
- name: Commit changelog update
run: |
echo "${{ needs.generate-changelog.outputs.patch }}" | git apply -
git ls-files --others --modified --exclude-standard | xargs git add
git add -u
git commit -m "chore(changelog): v${{ needs.get-version.outputs.version }}"
- name: Update version in composer.json
run: |
jq ".version = \"${{ needs.get-version.outputs.version }}\"" composer.json > composer.json.tmp && mv composer.json.tmp composer.json
git ls-files --others --modified --exclude-standard | xargs git add
git add -u
git commit -m "chore(tag): v${{ needs.get-version.outputs.version }}"
- name: "Push to branch `tag/v${{ needs.get-version.outputs.version }}`"
run: |
git push --set-upstream origin "tag/v${{ needs.get-version.outputs.version }}"
- name: "Open pull request: chore(release): `v${{ needs.get-version.outputs.version }}`"
env:
GH_TOKEN: ${{ secrets.TR_GH_TOKEN }}
run: |
gh pr create --title 'chore(release): `v${{ needs.get-version.outputs.version }}`' --body 'Release `v${{ needs.get-version.outputs.version }}`' --base main --head "tag/v${{ needs.get-version.outputs.version }}"