From 52e63cef6d088a328f3d303898c8bc8ba15f6904 Mon Sep 17 00:00:00 2001 From: sushi-chaaaan Date: Mon, 1 Jul 2024 23:24:48 +0900 Subject: [PATCH 01/10] ci: add release workflow draft --- .github/workflows/release.yml | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dc2c9da --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,64 @@ +name: release + +on: + workflow_dispatch: + +defaults: + run: + shell: bash + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-22.04 + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: setup CPython + uses: actions/setup-python@v5 + with: + cache: "pip" + cache-dependency-path: "requirements-dev.lock" + python-version-file: ".python-version" + + - name: install dependencies + id: install + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.lock + + - name: lint + if: ${{ always() && steps.install.outcome == 'success' }} + run: | + ruff check --output-format github . + + - name: format + if: ${{ always() && steps.install.outcome == 'success' }} + run: | + ruff format --check . + + release: + runs-on: ubuntu-22.04 + needs: check + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: setup CPython + uses: actions/setup-python@v5 + with: + cache: "pip" + cache-dependency-path: "requirements.lock" + python-version-file: ".python-version" + + - name: install dependencies + id: install + run: | + python -m pip install --upgrade pip + pip install -r requirements.lock + + # ここから自動リリース用の処理を記述 From 91d293b397784a96d204bb10afecb75d5db60b40 Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 17:30:51 +0900 Subject: [PATCH 02/10] set unused version to pyproject --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 18f98d0..4d95753 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "python-template" -version = "0.1.0" +version = "latest" description = "Add your description here" authors = [{ name = "sushi-chaaaan", email = "mail@sushichan.live" }] dependencies = [] From 7a978ee400664b5af89edca8416b66597efd742e Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 18:00:22 +0900 Subject: [PATCH 03/10] add release workflow --- .github/workflows/release.yml | 56 ++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc2c9da..3e3d9c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,18 @@ name: release on: + # release: + # types: + # - created workflow_dispatch: + inputs: + version: + description: "バージョン情報(A.B.C / A.B.C-preview.D)" + required: true + prerelease: + description: "プレリリースかどうか" + type: boolean + default: true defaults: run: @@ -12,6 +23,20 @@ concurrency: cancel-in-progress: true jobs: + config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる. + runs-on: ubuntu-latest + outputs: + version: ${{ steps.vars.outputs.version }} + version_or_latest: ${{ steps.vars.outputs.version_or_latest }} + steps: + - name: Declare variables + id: vars + run: | + : # release タグ名, または workflow_dispatch でのバージョン名. リリースでない (push event) 場合は空文字列 + echo "version=${{ github.event.release.tag_name || github.event.inputs.version }}" >> "$GITHUB_OUTPUT" + : # release タグ名, または workflow_dispatch でのバージョン名, または 'latest' + echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}" >> "$GITHUB_OUTPUT" + check: runs-on: ubuntu-22.04 steps: @@ -43,7 +68,9 @@ jobs: release: runs-on: ubuntu-22.04 - needs: check + needs: + - config + - check steps: - name: Check out the repository uses: actions/checkout@v4 @@ -62,3 +89,30 @@ jobs: pip install -r requirements.lock # ここから自動リリース用の処理を記述 + - name: Replace version + run: | + set -eux + sed -i "s/version = "latest"/version = \"${{ needs.config.outputs.version_or_latest }}\"/" pyproject.toml + + - name: Extract package name + id: package_name + run: | + set -eux + PACKAGE_NAME=$(cat pyproject.toml | grep -xoE "name = \"(.*?)\"" | sed -r 's/name = "(.*?)"/\1/') + echo "package_name=${package_name}_${{ needs.config.outputs.version_or_latest }}" >> "$GITHUB_OUTPUT" + + - name: Packaging + run: | + set -eux + zip -r ${{ steps.package_name.output.package_name }}.zip src/ + + - name: Create release + if: needs.config.outputs.version != '' + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + prerelease: ${{ github.event.inputs.prerelease }} + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ needs.config.outputs.version }} + artifacts: ${{ steps.package_name.output.package_name }}.zip + commit: ${{ github.sha }} From 7253253bbe6d2c4561d84c02f9f1cd8569a9cf2c Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 18:05:32 +0900 Subject: [PATCH 04/10] use 999.999.999 (ruf 200) --- .github/workflows/release.yml | 6 +++--- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e3d9c1..eefdbcf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,8 +34,8 @@ jobs: run: | : # release タグ名, または workflow_dispatch でのバージョン名. リリースでない (push event) 場合は空文字列 echo "version=${{ github.event.release.tag_name || github.event.inputs.version }}" >> "$GITHUB_OUTPUT" - : # release タグ名, または workflow_dispatch でのバージョン名, または 'latest' - echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}" >> "$GITHUB_OUTPUT" + : # release タグ名, または workflow_dispatch でのバージョン名, または '999.999.999' + echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || '999.999.999' }}" >> "$GITHUB_OUTPUT" check: runs-on: ubuntu-22.04 @@ -92,7 +92,7 @@ jobs: - name: Replace version run: | set -eux - sed -i "s/version = "latest"/version = \"${{ needs.config.outputs.version_or_latest }}\"/" pyproject.toml + sed -i "s/version = "999.999.999"/version = \"${{ needs.config.outputs.version_or_latest }}\"/" pyproject.toml - name: Extract package name id: package_name diff --git a/pyproject.toml b/pyproject.toml index 4d95753..9add21b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "python-template" -version = "latest" +version = "999.999.999" description = "Add your description here" authors = [{ name = "sushi-chaaaan", email = "mail@sushichan.live" }] dependencies = [] From 188e2adc582d7f6ce4e30212d8ed30c0726002df Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 18:09:21 +0900 Subject: [PATCH 05/10] fix miss --- .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 eefdbcf..cf23fe1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,7 +99,7 @@ jobs: run: | set -eux PACKAGE_NAME=$(cat pyproject.toml | grep -xoE "name = \"(.*?)\"" | sed -r 's/name = "(.*?)"/\1/') - echo "package_name=${package_name}_${{ needs.config.outputs.version_or_latest }}" >> "$GITHUB_OUTPUT" + echo "package_name=${PACKAGE_NAME}_${{ needs.config.outputs.version_or_latest }}" >> "$GITHUB_OUTPUT" - name: Packaging run: | From 377587af0b130213319f0db9323425b0fde51cfb Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 18:32:09 +0900 Subject: [PATCH 06/10] fix miss --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cf23fe1..5437e3b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -104,7 +104,7 @@ jobs: - name: Packaging run: | set -eux - zip -r ${{ steps.package_name.output.package_name }}.zip src/ + zip -r ${{ steps.package_name.outputs.package_name }}.zip src/ - name: Create release if: needs.config.outputs.version != '' @@ -114,5 +114,5 @@ jobs: prerelease: ${{ github.event.inputs.prerelease }} token: ${{ secrets.GITHUB_TOKEN }} tag: ${{ needs.config.outputs.version }} - artifacts: ${{ steps.package_name.output.package_name }}.zip + artifacts: ${{ steps.package_name.outputs.package_name }}.zip commit: ${{ github.sha }} From 868aa7b4a22740740e289beb5a17d8244af35e0d Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 18:32:20 +0900 Subject: [PATCH 07/10] add release note --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5437e3b..db072f6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -116,3 +116,4 @@ jobs: tag: ${{ needs.config.outputs.version }} artifacts: ${{ steps.package_name.outputs.package_name }}.zip commit: ${{ github.sha }} + body: ${{ steps.tag_version.outputs.changelog }} From 50dd10a736901e9f005f6eb73df0453b45a7a8b2 Mon Sep 17 00:00:00 2001 From: y-chan Date: Mon, 15 Jul 2024 19:59:57 +0900 Subject: [PATCH 08/10] add contents write permission --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index db072f6..e56a593 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,9 @@ on: type: boolean default: true +permissions: + contents: write + defaults: run: shell: bash @@ -104,7 +107,7 @@ jobs: - name: Packaging run: | set -eux - zip -r ${{ steps.package_name.outputs.package_name }}.zip src/ + zip -r ${{ steps.package_name.outputs.package_name }}.zip src/ pyproject.toml - name: Create release if: needs.config.outputs.version != '' From 61cb8041f6faf55322ff73eee590f7230d068b01 Mon Sep 17 00:00:00 2001 From: y-chan Date: Tue, 16 Jul 2024 02:03:23 +0900 Subject: [PATCH 09/10] appy suggestion --- .github/workflows/release.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e56a593..f52b71d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,9 +36,9 @@ jobs: id: vars run: | : # release タグ名, または workflow_dispatch でのバージョン名. リリースでない (push event) 場合は空文字列 - echo "version=${{ github.event.release.tag_name || github.event.inputs.version }}" >> "$GITHUB_OUTPUT" + echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT" : # release タグ名, または workflow_dispatch でのバージョン名, または '999.999.999' - echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || '999.999.999' }}" >> "$GITHUB_OUTPUT" + echo "version_or_latest=${{ github.event.inputs.version || '999.999.999' }}" >> "$GITHUB_OUTPUT" check: runs-on: ubuntu-22.04 @@ -95,13 +95,13 @@ jobs: - name: Replace version run: | set -eux - sed -i "s/version = "999.999.999"/version = \"${{ needs.config.outputs.version_or_latest }}\"/" pyproject.toml + sed -i 's/version = "999.999.999"/version = \"${{ needs.config.outputs.version_or_latest }}\"/' pyproject.toml - name: Extract package name id: package_name run: | set -eux - PACKAGE_NAME=$(cat pyproject.toml | grep -xoE "name = \"(.*?)\"" | sed -r 's/name = "(.*?)"/\1/') + PACKAGE_NAME=$(grep -xoE "name = \"(.*?)\"" pyproject.toml | sed -r 's/name = "(.*?)"/\1/') echo "package_name=${PACKAGE_NAME}_${{ needs.config.outputs.version_or_latest }}" >> "$GITHUB_OUTPUT" - name: Packaging @@ -119,4 +119,3 @@ jobs: tag: ${{ needs.config.outputs.version }} artifacts: ${{ steps.package_name.outputs.package_name }}.zip commit: ${{ github.sha }} - body: ${{ steps.tag_version.outputs.changelog }} From 8d708ae690bd2f95f37ccd90294cbb7d25bbacb4 Mon Sep 17 00:00:00 2001 From: Yuto Ashida Date: Tue, 16 Jul 2024 02:04:21 +0900 Subject: [PATCH 10/10] specity os Co-authored-by: Kentaro Suzuki --- .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 f52b71d..fac71b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ concurrency: jobs: config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる. - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: version: ${{ steps.vars.outputs.version }} version_or_latest: ${{ steps.vars.outputs.version_or_latest }}