From 7e98de92333c12c9a7e827bd2d837c2b334a8136 Mon Sep 17 00:00:00 2001 From: rot1024 Date: Fri, 10 Jun 2022 12:32:00 +0900 Subject: [PATCH] ci: set up release workflow for release branch (#243) * fix pr_title workflow * add test workflow * update release workflow * fix action * fix config * fix action * fix [ci skip] * fix * fix * update * update * add stage workflow * fix --- .github/changelog.json | 17 +++++++ .github/cliff.toml | 58 ------------------------ .github/pr-title-checker-config.json | 7 --- .github/workflows/build.yml | 18 ++++---- .github/workflows/ci.yml | 11 ++--- .github/workflows/e2e.yml | 9 ++-- .github/workflows/pr_title.yml | 2 +- .github/workflows/release.yml | 68 +++++++++------------------- .github/workflows/stage.yml | 24 ++++++++++ 9 files changed, 83 insertions(+), 131 deletions(-) create mode 100644 .github/changelog.json delete mode 100644 .github/cliff.toml delete mode 100644 .github/pr-title-checker-config.json create mode 100644 .github/workflows/stage.yml diff --git a/.github/changelog.json b/.github/changelog.json new file mode 100644 index 0000000000..1a3a4b7cea --- /dev/null +++ b/.github/changelog.json @@ -0,0 +1,17 @@ +{ + "prefix": { + "feat": "๐Ÿš€ Features", + "fix": "๐Ÿ”ง Bug Fixes", + "docs": "๐Ÿ“– Documentation", + "doc": "๐Ÿ“– Documentation", + "perf": "โšก๏ธ Performance", + "refactor": "โœจ Refactor", + "style": "๐ŸŽจ Styling", + "test": "๐Ÿงช Testing", + "chore": "Miscellaneous Tasks", + "build": "Miscellaneous Tasks", + "deps": "Miscellaneous Tasks", + "ci": false, + "revert": false + } +} diff --git a/.github/cliff.toml b/.github/cliff.toml deleted file mode 100644 index 3ae631fbe3..0000000000 --- a/.github/cliff.toml +++ /dev/null @@ -1,58 +0,0 @@ -# configuration file for git-cliff (0.1.0) - -[changelog] -# changelog header -header = """ -# Changelog -All notable changes to this project will be documented in this file.\n -""" -# template for the changelog body -# https://tera.netlify.app/docs/#introduction -body = """ -{% if version %}\ - ## {{ version | replace(from="v", to="") }} - {{ timestamp | date(format="%Y-%m-%d") }} -{% else %}\ - ## Unreleased -{% endif %}\ -{% for group, commits in commits | group_by(attribute="group") %} - ### {{ group }} - {% for commit in commits %} - - {{ commit.message | replace(from=" [ci skip]", to="") | replace(from=" [skip ci]", to="") | upper_first }} `{{ commit.id | split(pat="") | slice(end=7) | join(sep="") }}`\ - {% endfor %} -{% endfor %}\n -""" -# remove the leading and trailing whitespaces from the template -trim = true -# changelog footer -footer = """ - -""" - -[git] -# allow only conventional commits -# https://www.conventionalcommits.org -conventional_commits = true -# regex for parsing and grouping commits -commit_parsers = [ - { message = "^feat", group = "๐Ÿš€ Features"}, - { message = "^fix", group = "๐Ÿ”ง Bug Fixes"}, - { message = "^docs", group = "๐Ÿ“– Documentation"}, - { message = "^doc", group = "๐Ÿ“– Documentation"}, - { message = "^perf", group = "โšก๏ธ Performance"}, - { message = "^refactor", group = "โœจ Refactor"}, - { message = "^style", group = "๐ŸŽจ Styling"}, - { message = "^test", group = "๐Ÿงช Testing"}, - { body = ".*security", group = "๐Ÿ”’ Security"}, - { message = "^chore", group = "Miscellaneous Tasks"}, - { message = "^build", group = "Miscellaneous Tasks"}, - { message = "^deps", group = "Miscellaneous Tasks"}, - { message = "^ci", skip = true}, - { message = "^revert", skip = true}, - { message = "^v[0-9]+", skip = true}, -] -# filter out the commits that are not matched by commit parsers -filter_commits = false -# glob pattern for matching git tags -tag_pattern = "v[0-9]*" -# regex for skipping tags -skip_tags = "v0.1.0-beta.1" diff --git a/.github/pr-title-checker-config.json b/.github/pr-title-checker-config.json deleted file mode 100644 index 1f9f9c8262..0000000000 --- a/.github/pr-title-checker-config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "CHECKS": { - "regexp": "^(?:feat|fix|docs|style|refactor|pref|test|build|ci|chore|revert): ", - "regexpFlags": "i", - "ignoreLabels" : ["meta"] - } -} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c2c2c28c5f..3b4248b580 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,15 +3,16 @@ on: workflow_run: workflows: [ci] types: [completed] - branches: [main] + branches: [main, release] jobs: info: name: Collect information runs-on: ubuntu-latest outputs: new_tag: ${{ steps.info.outputs.new_tag }} + branch: ${{ steps.info.outputs.branch }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Fetch tags run: git fetch --prune --unshallow --tags - name: Get info @@ -22,6 +23,7 @@ jobs: if [[ ! -z "$TAG" ]]; then echo "::set-output name=new_tag::$TAG" fi + echo "::set-output name=branch::`git branch --show-current`" - name: Show info env: NEW_TAG: ${{ steps.info.outputs.new_tag }} @@ -32,14 +34,14 @@ jobs: needs: - info steps: - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: - node-version: "14.x" - - uses: actions/checkout@v2 + node-version: lts/* + - uses: actions/checkout@v3 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v3 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} @@ -62,7 +64,7 @@ jobs: needs: - info - build - if: "!needs.info.outputs.new_tag" + if: ${{ needs.info.outputs.branch == 'main' && !needs.info.outputs.new_tag }} env: ARTIFACT: reearth-web.tar.gz ARTIFACT_NEW: reearth-web_nightly.tar.gz @@ -90,7 +92,7 @@ jobs: needs: - info - build - if: needs.info.outputs.new_tag + if: ${{ needs.info.outputs.branch == 'release' && needs.info.outputs.new_tag }} env: ARTIFACT: reearth-web.tar.gz ARTIFACT_NEW: reearth-web_${{ needs.info.outputs.new_tag }}.tar.gz diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72725bbbb7..74049dfcdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI on: push: - branches: [main] + branches: [main, release] tags-ignore: ["*"] pull_request: concurrency: @@ -12,15 +12,14 @@ jobs: name: CI runs-on: ubuntu-latest steps: - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: - node-version: "14.x" - - name: Checkout - uses: actions/checkout@v2 + node-version: lts/* + - uses: actions/checkout@v3 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v3 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 17e935f47c..5c3f44fd98 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -20,15 +20,14 @@ jobs: needs: e2e_pre if: needs.e2e_pre.outputs.result != null steps: - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: - node-version: '14.x' - - name: checkout - uses: actions/checkout@v2 + node-version: lts/* + - uses: actions/checkout@v3 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v3 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/pr_title.yml b/.github/workflows/pr_title.yml index f10e029337..db688eb901 100644 --- a/.github/workflows/pr_title.yml +++ b/.github/workflows/pr_title.yml @@ -8,7 +8,7 @@ on: - labeled - unlabeled jobs: - check: + pr_title: runs-on: ubuntu-latest steps: - uses: actions/github-script@v6 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 00c6af26e2..b747393bb2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,73 +2,49 @@ name: Release on: workflow_dispatch: inputs: - custom_tag: + version: required: false - description: Specify version only when you want to increment the minor and major version (e.g. 1.1.0) + description: 'Next version (NOTE: Switch the branch to "release"!)' + type: choice + default: minor + options: + - patch + - minor + - major jobs: release: name: Release runs-on: ubuntu-latest + if: github.ref == 'refs/heads/release' steps: - name: Set up git config run: | git config --global user.name "${{ github.actor }}" git config --global user.email "${{ github.actor }}@users.noreply.github.com" - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 token: ${{ secrets.GPT }} - - name: Bump tag version - id: tag - uses: mathieudutour/github-tag-action@v5.6 + - id: changelog + name: Generate CHANGELOG + uses: reearth/changelog-action@main with: - github_token: ${{ secrets.GITHUB_TOKEN }} - custom_tag: ${{ github.event.inputs.custom_tag }} - dry_run: true - - name: Update version of package.json + version: ${{ github.event.inputs.version }} + repo: ${{ github.repository }} + latest: true + - name: Update package.json version env: - TAG: ${{ steps.tag.outputs.new_tag }} + VERSION: ${{ steps.changelog.outputs.version }} run: | - yarn version --no-git-tag-version --new-version ${TAG/v} - - name: Prepare git-cliff - run: touch CHANGELOG.md - - name: Generate changelog - uses: orhun/git-cliff-action@v1 - env: - OUTPUT: CHANGELOG.md - with: - config: .github/cliff.toml - args: --verbose --tag ${{ steps.tag.outputs.new_tag }} - - name: Format changelogs - env: - URL: ${{ github.event.repository.html_url }} - run: | - URL=${URL//\//\\\/} - sed -i -E 's///g; s/\(#([0-9]+)\)/([#\1]('"$URL"'\/pull\/\1))/g; s/`([a-zA-Z0-9]+)`/[`\1`]('"$URL"'\/commit\/\1)/g' CHANGELOG*.md - - name: Generate CHANGELOG_latest.md - uses: actions/github-script@v5 - with: - script: | - const fs = require("fs"); - const changelog = fs.readFileSync("CHANGELOG.md", "utf8"); - const lines = changelog.split("\n"); - const h = lines - .map((l, i) => [l, i]) - .filter(l => l[0].startsWith("## ")) - .map(l => l[1]) - .slice(0, 2); - if (!h.length) throw new Error("failed to get the changelog of the latest version"); - const m = lines.slice(h[0] + 1, h[1]).join("\n"); - fs.writeFileSync("CHANGELOG_latest.md", m); - - name: Upload latest changelog + yarn version --no-git-tag-version --new-version ${VERSION/v} + - name: Upload latest CHANGELOG uses: actions/upload-artifact@v2 with: - name: changelog-${{ steps.tag.outputs.new_tag }} + name: changelog-${{ steps.changelog.outputs.version }} path: CHANGELOG_latest.md - name: Commit & push env: - TAG: ${{ steps.tag.outputs.new_tag }} + TAG: ${{ steps.changelog.outputs.version }} run: | rm CHANGELOG_latest.md git add CHANGELOG.md diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 0000000000..55f8e616d8 --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,24 @@ +name: Stage +on: + workflow_dispatch: +jobs: + stage: + runs-on: ubuntu-latest + if: github.ref === "refs/heads/main" + steps: + - name: git config + env: + GPT_USER: ${{ secrets.GPT_USER }} + run: | + git config --global user.name $GPT_USER + git config --global pull.rebase false + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GPT }} + - name: Checkout release branch + run: git checkout release + - name: Merge main branch to release branch + run: git merge -X theirs main + - name: Git push + run: git push origin release