Skip to content

Commit

Permalink
ci: update release workflow (#13)
Browse files Browse the repository at this point in the history
* ci: add workflow for creating pull request for release
* ci: remove function for generating changelog from check_pr
* ci: changed to include change log in release notes
  • Loading branch information
mato533 authored Oct 20, 2024
1 parent 6dfce70 commit 354b5e0
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 37 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/[email protected]

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Generate changelog
run: |
pnpm run changelog -c github
pnpm exec prettier --write CHANGELOG.md
- name: Create Release
id: create_release
Expand All @@ -91,3 +110,4 @@ jobs:
release_name: ${{ github.ref_name }}
draft: true
prerelease: false
body_path: CHANGELOG.md
42 changes: 11 additions & 31 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ jobs:
else
echo "Changes detected."
git add .
git commit -m "style: format and lint source codes" -m "[AUTO]"
git commit -F-<<EOF
style: format and lint source codes
[AUTO] this commit is created by github actions automatialy.
EOF
RESULT="${VAR_NAME_FOR_CHANGED}=1"
fi
echo "${RESULT}">>"${GITHUB_OUTPUT}"
Expand Down Expand Up @@ -136,50 +140,26 @@ jobs:
else
echo "Changes detected."
git add .
git commit -m "chore: update version of package.json" -m "[AUTO]"
RESULT="${VAR_NAME_FOR_CHANGED}=1"
fi
echo "${RESULT}">>"${GITHUB_OUTPUT}"
echo "${RESULT}"
git commit -F-<<EOF
chore: update version of package.json
- name: Generate a changelog
env:
APP_VERSION: ${{ needs.get-version.outputs.app-version }}
run: |
echo "Update changelog"
pnpm run changelog --tag ${APP_VERSION}
pnpm exec prettier --write CHANGELOG.md
- name: Check if there are any changes
id: check-changes-changelog
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
IS_CHANGED: ${{ steps.check-changes-package-json.outputs.done-change }}
run: |
git add -N .
OLD_VALUE="${IS_CHANGED}"
if git diff --exit-code --quiet; then
echo "No changes detected."
RESULT="${VAR_NAME_FOR_CHANGED}=${OLD_VALUE}"
else
echo "Changes detected."
git add .
git commit -m "chore: update CHANGELOG.md" -m "[AUTO]"
[AUTO] this commit is created by github actions automatialy.
EOF
RESULT="${VAR_NAME_FOR_CHANGED}=1"
fi
echo "${RESULT}">>"${GITHUB_OUTPUT}"
echo "${RESULT}"
- name: push
if: ${{ steps.check-changes-changelog.outputs.done-change > 0 }}
if: ${{ steps.check-changes-package-json.outputs.done-change > 0 }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: git push

- name: Set the output
id: result
env:
IS_UPDATED: '${{ steps.check-changes-changelog.outputs.done-change }}'
IS_UPDATED: '${{ steps.check-changes-package-json.outputs.done-change }}'
run: |
RESULT="is-updated=${IS_UPDATED}"
echo "${RESULT}">>"${GITHUB_OUTPUT}"
Expand Down
136 changes: 136 additions & 0 deletions .github/workflows/create-rlease-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Bump Version

on:
workflow_dispatch:
inputs:
version-type:
description: 'Select version type'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
GH_USER: 'github-actions[bot]'

jobs:
bump-version:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
contents: write
pull-requests: write
env:
VERSION_TYPE: ${{ github.event.inputs.version-type }}
steps:
- run: |
git config --global user.name "${GH_USER}"
git config --global user.email "${GH_EMAIL}"
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/[email protected]

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Display selected version type
run: echo "Selected version type-> ${VERSION_TYPE}"

# You can add your own logic here based on the selected version type
- name: Bump version based on input
run: |
case "${VERSION_TYPE}" in
major)
echo "Bumping major version"
pnpm version major --no-commit-hooks --no-git-tag-version
;;
minor)
echo "Bumping minor version"
pnpm version minor --no-commit-hooks --no-git-tag-version
;;
patch)
echo "Bumping patch version"
pnpm version minor --no-commit-hooks --no-git-tag-version
;;
esac
- name: Parse package.json
id: identify-version
run: |
APP_VERSION="$(cat ./package.json |jq .version|sed -e 's/"//g'| head -n1)"
if [ ! -n "${APP_VERSION}" ]; then
exit 255
fi
echo "Detected the version: ${APP_VERSION}"
echo "app-version=${APP_VERSION}" >>"${GITHUB_OUTPUT}"
echo "app-version-text=v${APP_VERSION}" >>"${GITHUB_OUTPUT}"
- name: Check if there are any changes
run: |
git add -N .
if git diff --exit-code --quiet; then
echo "No changes detected."
echo "ERROR: could not update the package.json"
exit 1
else
echo "Changes detected."
fi
- name: Checkout new repository
env:
APP_VERSION: ${{steps.identify-version.outputs.app-version}}
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
BRANCH_NAME="release/${APP_VERSION_TEXT}"
git checkout -b "${BRANCH_NAME}"
- name: Update the changelog
env:
APP_VERSION: ${{steps.identify-version.outputs.app-version}}
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
pnpm run changelog --tag "${APP_VERSION_TEXT}"
pnpm exec prettier --write CHANGELOG.md
git add CHANGELOG.md
git commit -F-<<EOF
chore: update the CHANGELOG.md for ${APP_VERSION_TEXT}
[AUTO] this commit is created by github actions automatialy.
EOF
- name: Commit package.json
env:
APP_VERSION: ${{steps.identify-version.outputs.app-version}}
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
git add package.json
git commit -F-<<EOF
chore: update version of package.json for ${APP_VERSION_TEXT}
[AUTO] this commit is created by github actions automatialy.
EOF
- name: Push commits
run: |
git push -u origin "${BRANCH_NAME}"
- name: Create pull request
env:
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
gh pr create --title "chore(release): ${APP_VERSION_TEXT}" --body "**Preparations for ${APP_VERSION_TEXT}**"
7 changes: 1 addition & 6 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ body = """
{% for group, commits in commits | filter(attribute="merge_commit", value=false) | group_by(attribute="group") %}
### {{ group | striptags | trim | upper_first }}
{% for commit in commits %}
{% if commit.message is matching("\\[(\\w+\\s)?#([0-9]+)\\]") %}\
{# pass #}\
{% else %}\
{% continue %}\
{% endif %}\
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
{% if commit.breaking %}[**breaking**] {% endif %}\
{{ commit.message | upper_first }}\
Expand Down Expand Up @@ -71,7 +66,7 @@ commit_parsers = [
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
{ message = "^chore\\(release\\): prepare for", skip = true },
#{ message = "^chore\\(release\\): prepare for", skip = true },
{ message = "^chore\\(deps.*\\)", skip = true },
{ message = "^chore\\(pr\\)", skip = true },
{ message = "^chore\\(pull\\)", skip = true },
Expand Down

0 comments on commit 354b5e0

Please sign in to comment.