Skip to content

Commit 7dfe203

Browse files
committed
ci: 新しいリリースワークフローに移行
- bump-version.yml: 自動バージョニングとGitHubリリース作成 - publish.yml: Sonatype Central Portalへの自動公開 - 古いrelease.ymlとsnapshot.ymlを削除
1 parent 0dd02fd commit 7dfe203

File tree

4 files changed

+103
-85
lines changed

4 files changed

+103
-85
lines changed

.github/workflows/bump-version.yml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,68 @@ name: Bump Version
22
on:
33
workflow_dispatch:
44
inputs:
5-
force:
6-
description: 'force release'
7-
required: false
8-
default: '0'
5+
force_bump:
6+
description: 'Force version bump'
7+
required: true
8+
type: boolean
9+
default: false
910
schedule:
1011
- cron: '0 0 * * *'
1112
jobs:
1213
bump-version:
1314
runs-on: ubuntu-latest
1415
steps:
15-
- uses: actions/checkout@v5.0.0
16+
- uses: actions/checkout@v5
1617
with:
1718
fetch-depth: 0
1819
persist-credentials: false
1920
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2021
- name: Calculate changes from the latest tag to HEAD
2122
id: changes
2223
run: |
23-
LATEST_TAG=$(git describe --abbrev=0 --tags)
24-
echo "latest-tag = $LATEST_TAG"
25-
COUNT=$(git log $LATEST_TAG..HEAD --pretty=format:"%s" --no-merges \
26-
--grep='^build:' \
27-
--grep='^ci:' \
28-
--grep='^feat:' \
29-
--grep='^fix:' \
30-
--grep='^docs:' \
31-
--grep='^style:' \
32-
--grep='^refactor:' \
33-
--grep='^perf:' \
34-
--grep='^test:' \
35-
--grep='^revert:' \
36-
--grep='^chore:' | awk 'END{print NR}')
24+
# タグが存在するか確認
25+
if git tag -l | grep -q .; then
26+
LATEST_TAG=$(git describe --abbrev=0 --tags)
27+
echo "latest-tag = $LATEST_TAG"
28+
# 最新タグから現在までの変更をカウント
29+
COUNT=$(git log $LATEST_TAG..HEAD --pretty=format:"%s" --no-merges \
30+
--grep='^build:' \
31+
--grep='^ci:' \
32+
--grep='^feat:' \
33+
--grep='^fix:' \
34+
--grep='^docs:' \
35+
--grep='^style:' \
36+
--grep='^refactor:' \
37+
--grep='^perf:' \
38+
--grep='^test:' \
39+
--grep='^revert:' \
40+
--grep='^chore:' | awk 'END{print NR}')
41+
else
42+
echo "No tags found - using initial commit as base"
43+
# 初期コミットから現在までの変更をカウント(初回実行時)
44+
FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD)
45+
COUNT=$(git log $FIRST_COMMIT..HEAD --pretty=format:"%s" --no-merges \
46+
--grep='^build:' \
47+
--grep='^ci:' \
48+
--grep='^feat:' \
49+
--grep='^fix:' \
50+
--grep='^docs:' \
51+
--grep='^style:' \
52+
--grep='^refactor:' \
53+
--grep='^perf:' \
54+
--grep='^test:' \
55+
--grep='^revert:' \
56+
--grep='^chore:' | awk 'END{print NR}')
57+
# 初回は必ず1以上にしてタグ付けができるようにする
58+
if [ "$COUNT" -eq "0" ]; then
59+
COUNT=1
60+
fi
61+
fi
3762
echo "steps.changes.outputs.count = $COUNT"
38-
FORCE=${{ inputs.force }}
39-
if [[ "$FORCE" = "1" ]]; then
40-
echo "::set-output name=count::1"
63+
if [[ "${{ inputs.force_bump }}" == "true" ]]; then
64+
echo "count=1" >> $GITHUB_OUTPUT
4165
else
42-
echo "::set-output name=count::$COUNT"
66+
echo "count=$COUNT" >> $GITHUB_OUTPUT
4367
fi
4468
- name: Bump version and push tag
4569
id: tag_version
@@ -56,4 +80,4 @@ jobs:
5680
tag_name: ${{ steps.tag_version.outputs.new_tag }}
5781
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
5882
body: ${{ steps.tag_version.outputs.changelog }}
59-
if: steps.changes.outputs.count > 0
83+
if: steps.changes.outputs.count > 0

.github/workflows/publish.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: publish
2+
on:
3+
push:
4+
tags: [ 'v*' ]
5+
branches: [ main ]
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
env:
10+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
11+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
12+
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
13+
steps:
14+
- uses: actions/checkout@v5
15+
with: { fetch-depth: 0 }
16+
- uses: actions/setup-java@v5
17+
with:
18+
distribution: temurin
19+
java-version: 17
20+
cache: sbt
21+
- uses: sbt/setup-sbt@v1
22+
- name: Configure Sonatype credentials
23+
run: |
24+
mkdir -p ~/.sbt/1.0
25+
cat > ~/.sbt/1.0/sonatype_credentials <<EOF
26+
realm=Sonatype Nexus Repository Manager
27+
host=central.sonatype.com
28+
user=$SONATYPE_USERNAME
29+
password=$SONATYPE_PASSWORD
30+
EOF
31+
- name: Import GPG key
32+
run: |
33+
echo "${{ secrets.PGP_SECRET }}" | base64 -d | gpg --batch --import
34+
- name: Publish Release JAR
35+
if: startsWith(github.ref,'refs/tags/v')
36+
run: |
37+
sbt \
38+
'set every publishTo := { val d = baseDirectory.value / "central-bundle"; Some("bundle" at s"file://${d.getAbsolutePath}") }' \
39+
+publishSigned
40+
PROJECT=$(basename "$GITHUB_REPOSITORY")
41+
VERSION=${GITHUB_REF_NAME##v}
42+
DATE_TIME=$(date +%Y%m%d-%H%M%S)
43+
ZIP_FILE="${PROJECT}-v${VERSION}-${DATE_TIME}.zip"
44+
(cd central-bundle && zip -rq ../"$ZIP_FILE" .)
45+
curl --fail-with-body -sS \
46+
-u "$SONATYPE_USERNAME:$SONATYPE_PASSWORD" \
47+
-F bundle=@"$ZIP_FILE" \
48+
-w "\nHTTP %{http_code}\n" \
49+
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC"
50+
- name: Publish Snapshot JAR
51+
if: github.ref == 'refs/heads/main'
52+
run: |
53+
sbt \
54+
'set every publishTo := Some("central-snapshots" at "https://central.sonatype.com/repository/maven-snapshots/")' \
55+
+publishSigned

.github/workflows/release.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/snapshot.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)