From b9f9de7eb4ef25ed0ba91b6251547ed43e73e034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E7=8C=AB?= Date: Sat, 17 Dec 2022 08:17:52 +0900 Subject: [PATCH 1/6] Increment version --- .github/workflows/increment-version.yml | 80 +++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/increment-version.yml diff --git a/.github/workflows/increment-version.yml b/.github/workflows/increment-version.yml new file mode 100644 index 0000000..ebdf703 --- /dev/null +++ b/.github/workflows/increment-version.yml @@ -0,0 +1,80 @@ +name: Increment version + +on: + workflow_dispatch: + inputs: + increment-version: + description: Increment version (Semantic Versioning) + required: true + default: patch + type: choice + options: + - major + - minor + - patch + +jobs: + increment-version: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Latest version + run: | + set -x + tag=$(gh api /repos/${GITHUB_REPOSITORY}/releases/latest --jq '.tag_name') + echo "LATEST_VERSION=$tag" >> $GITHUB_ENV + env: + GH_TOKEN: ${{ github.token }} + - name: Next version + id: next-version + run: | + set -x + + if [[ ${LATEST_VERSION} =~ ^(.*?)([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + prefix=${BASH_REMATCH[1]} + major=${BASH_REMATCH[2]} + minor=${BASH_REMATCH[3]} + patch=${BASH_REMATCH[4]} + else + exit 1 + fi + + case "$INCREMENT_VERSION" in + "major") + ((++major)); minor=0; patch=0;; + "minor") + ((++minor)); patch=0;; + "patch") + ((++patch));; + esac + + next_version="${prefix}${major}.${minor}.${patch}" + echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV + env: + INCREMENT_VERSION: ${{ github.event.inputs.increment-version }} + + - uses: actions/checkout@v3 + - name: Update README + id: version + run: | + set -x + sed -i -e "s|${GITHUB_REPOSITORY}@${LATEST_VERSION}|${GITHUB_REPOSITORY}@${NEXT_VERSION}|g" README.md + git diff + - uses: snow-actions/git-config-user@v1.0.0 + - id: generate-token + uses: tibdex/github-app-token@v1.7.0 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Commit & PR + run: | + set -x + branch="release/${NEXT_VERSION}" + git switch -c ${branch} + git add . + git commit -m "${NEXT_VERSION}" + git push origin ${branch} + gh pr create --base ${GITHUB_REF_NAME} --head ${branch} --assignee ${GITHUB_ACTOR} --title ${NEXT_VERSION} --body '' + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} From ff8651a01abeec46404fb82ac30dfaea1c7eb21e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E7=8C=AB?= Date: Sat, 17 Dec 2022 08:29:04 +0900 Subject: [PATCH 2/6] Release workflow --- .github/workflows/release.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/release.md diff --git a/.github/workflows/release.md b/.github/workflows/release.md new file mode 100644 index 0000000..eca9e24 --- /dev/null +++ b/.github/workflows/release.md @@ -0,0 +1,29 @@ +name: Release + +on: + pull_request: + types: [ closed ] + workflow_dispatch: + inputs: + version: + description: Semantic version (e.g. v1.0.0) + required: true + +jobs: + release: + if: >- + github.event_name == 'workflow_dispatch' || + github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') + runs-on: ubuntu-latest + timeout-minutes: 5 + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_BRANCH: ${{ github.event.pull_request.head.ref || github.event.inputs.version }} + + steps: + - name: Create release draft + id: release + run: | + version=${RELEASE_BRANCH#release/} + gh release create ${version} --title ${version} --generate-notes From 32321dba7d0c95fe7ce77bda8212b36df95492e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E7=8C=AB?= Date: Sat, 17 Dec 2022 08:29:23 +0900 Subject: [PATCH 3/6] Fix ext --- .github/workflows/{release.md => release.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{release.md => release.yml} (100%) diff --git a/.github/workflows/release.md b/.github/workflows/release.yml similarity index 100% rename from .github/workflows/release.md rename to .github/workflows/release.yml From 9a50cf14fbe18cac6999a28655ec59bb4cf5cb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E7=8C=AB?= Date: Sat, 17 Dec 2022 08:31:39 +0900 Subject: [PATCH 4/6] Released workflow --- .github/workflows/released.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/released.yml diff --git a/.github/workflows/released.yml b/.github/workflows/released.yml new file mode 100644 index 0000000..04fad34 --- /dev/null +++ b/.github/workflows/released.yml @@ -0,0 +1,23 @@ +name: Released + +on: + release: + types: [ released ] + +jobs: + tweet: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Tweet + uses: snow-actions/tweet@v1.3.0 + with: + status: | + Release ${{ github.event.release.name }} ยท ${{ github.repository }} + ${{ github.event.release.html_url }} + env: + CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + CONSUMER_API_SECRET_KEY: ${{ secrets.TWITTER_CONSUMER_API_SECRET_KEY }} + ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} From 2fc4a0a97481299bf435c77cddb6ad90f11bba6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E7=8C=AB?= Date: Sat, 17 Dec 2022 08:35:04 +0900 Subject: [PATCH 5/6] Use app token to trigger next workflow --- .github/workflows/release.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eca9e24..9c5502d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,14 +16,19 @@ jobs: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') runs-on: ubuntu-latest timeout-minutes: 5 - env: - GH_TOKEN: ${{ github.token }} - GH_REPO: ${{ github.repository }} - RELEASE_BRANCH: ${{ github.event.pull_request.head.ref || github.event.inputs.version }} steps: + - id: generate-token + uses: tibdex/github-app-token@v1.7.0 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} - name: Create release draft id: release run: | version=${RELEASE_BRANCH#release/} gh release create ${version} --title ${version} --generate-notes + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + GH_REPO: ${{ github.repository }} + RELEASE_BRANCH: ${{ github.event.pull_request.head.ref || github.event.inputs.version }} From 8efb6f83f0487ab71381b5cd0a3e2f2c92b1b7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=AA=E7=8C=AB?= Date: Sat, 17 Dec 2022 08:35:32 +0900 Subject: [PATCH 6/6] Fix description --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9c5502d..be7191c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: with: app_id: ${{ secrets.APP_ID }} private_key: ${{ secrets.APP_PRIVATE_KEY }} - - name: Create release draft + - name: Create release id: release run: | version=${RELEASE_BRANCH#release/}