Skip to content

feat: add publish release workflow #2

feat: add publish release workflow

feat: add publish release workflow #2

name: Prepare Release
on:
workflow_call:
inputs:
node-verions:
description: 'Node.js version to use.'
required: false
type: string
default: '20'
commit-user-name:
description: 'Git user name for commit'
required: false
type: string
default: 'github-actions[bot]'
commit-user-email:
description: 'Git user email for commit.'
required: false
type: string
default: 'github-actions[bot]@users.noreply.github.com'
secrets:
GITHUB_TOKEN:

Check failure on line 22 in .github/workflows/prepare-release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/prepare-release.yml

Invalid workflow file

secret name `GITHUB_TOKEN` within `workflow_call` can not be used since it would collide with system reserved name
required: true
description: 'GitHub Token for authentication.'
jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout Config
uses: actions/checkout@v4
with:
repository: 'leoweyr/github-release-workflow'
path: .change-log-config
sparse-checkout: cliff.toml
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-verions }}
- name: Set Environment Variables
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Create Release Branch
run: |
git config --global user.name "${{ inputs.commit-user-name }}"
git config --global user.email "${{ inputs.commit-user-email }}"
git checkout -b release/${{ env.TAG_NAME }}
- name: Generate Changelog Content for PR Body
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx git-cliff --config .change-log-config/cliff.toml --verbose --latest --strip all > pr_body_raw.md
- name: Save PR Body to File
run: |
cat pr_body_raw.md | tail -n +2 > pr_body_cleaned.md
- name: Update CHANGELOG.md File
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -f "CHANGELOG.md" ]; then
# File exists: Prepend new changes (git-cliff intelligently handles headers).
npx git-cliff --config .change-log-config/cliff.toml --verbose --latest --prepend CHANGELOG.md
else
# File missing: Create new with full history and header.
npx git-cliff --config .change-log-config/cliff.toml --verbose --output CHANGELOG.md
fi
- name: Commit and Push
run: |
git add CHANGELOG.md
git commit -m "release: ${{ env.TAG_NAME }}"
git push origin release/${{ env.TAG_NAME }}
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--title "release: ${{ env.TAG_NAME }}" \
--body-file pr_body_cleaned.md \
--base master \
--head release/${{ env.TAG_NAME }}