Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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

permissions:
contents: write

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる.
runs-on: ubuntu-latest
Comment thread
y-chan marked this conversation as resolved.
Outdated
outputs:
version: ${{ steps.vars.outputs.version }}
version_or_latest: ${{ steps.vars.outputs.version_or_latest }}
steps:
- name: <Setup> 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 でのバージョン名, または '999.999.999'
echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || '999.999.999' }}" >> "$GITHUB_OUTPUT"
Comment thread
y-chan marked this conversation as resolved.
Outdated

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:
- config
- 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

# ここから自動リリース用の処理を記述
- name: Replace version
run: |
set -eux
sed -i "s/version = "999.999.999"/version = \"${{ needs.config.outputs.version_or_latest }}\"/" pyproject.toml
Comment thread
y-chan marked this conversation as resolved.
Outdated

- name: Extract package name
id: package_name
run: |
set -eux
PACKAGE_NAME=$(cat pyproject.toml | grep -xoE "name = \"(.*?)\"" | sed -r 's/name = "(.*?)"/\1/')
Comment thread
sushichan044 marked this conversation as resolved.
Outdated
echo "package_name=${PACKAGE_NAME}_${{ needs.config.outputs.version_or_latest }}" >> "$GITHUB_OUTPUT"

- name: Packaging
run: |
set -eux
zip -r ${{ steps.package_name.outputs.package_name }}.zip src/ pyproject.toml

- 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.outputs.package_name }}.zip
commit: ${{ github.sha }}
body: ${{ steps.tag_version.outputs.changelog }}
Comment thread
y-chan marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "python-template"
version = "0.1.0"
version = "999.999.999"
description = "Add your description here"
authors = [{ name = "sushi-chaaaan", email = "mail@sushichan.live" }]
dependencies = []
Expand Down