From 354b5e0e24d95c4c25199795a240f956e8434c11 Mon Sep 17 00:00:00 2001 From: mato533 <35281743+mato533@users.noreply.github.com> Date: Sun, 20 Oct 2024 23:37:49 +0900 Subject: [PATCH] ci: update release workflow (#13) * 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 --- .github/workflows/build.yml | 20 ++++ .github/workflows/check_pr.yml | 42 ++------ .github/workflows/create-rlease-pr.yml | 136 +++++++++++++++++++++++++ cliff.toml | 7 +- 4 files changed, 168 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/create-rlease-pr.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ebcc10d..e03368c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,6 +80,25 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install pnpm + uses: pnpm/action-setup@v4.0.0 + + - 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 @@ -91,3 +110,4 @@ jobs: release_name: ${{ github.ref_name }} draft: true prerelease: false + body_path: CHANGELOG.md diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index 76fcbf6..9da0a28 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -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-<>"${GITHUB_OUTPUT}" @@ -136,42 +140,18 @@ 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-<>"${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 @@ -179,7 +159,7 @@ jobs: - 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}" diff --git a/.github/workflows/create-rlease-pr.yml b/.github/workflows/create-rlease-pr.yml new file mode 100644 index 0000000..7655f4a --- /dev/null +++ b/.github/workflows/create-rlease-pr.yml @@ -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/action-setup@v4.0.0 + + - 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-<