Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
74 changes: 70 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,77 @@
name: Build & Release

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+" # e.g. 1.2.0
workflow_dispatch:
inputs:
version:
description: "Release version, e.g. 1.2.0"
required: true
type: string

permissions:
contents: write # needed to create GitHub Releases

jobs:
prepare-release:
runs-on: ubuntu-latest
outputs:
release_sha: ${{ steps.release-ref.outputs.release_sha }}
version: ${{ steps.release-ref.outputs.version }}
env:
RELEASE_VERSION: ${{ inputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Validate release branch and version
shell: bash
run: |
if [[ "${{ github.ref_type }}" != "branch" ]]; then
echo "Release workflow must be run from a branch."
exit 1
fi
if [[ ! "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Version must be semver without a leading v, e.g. 1.2.0 or 1.2.0-beta.1"
exit 1
fi
if git ls-remote --exit-code --tags origin "$RELEASE_VERSION" >/dev/null 2>&1; then
echo "Tag $RELEASE_VERSION already exists."
exit 1
fi

- name: Set package version
shell: bash
run: npm version "$RELEASE_VERSION" --no-git-tag-version --allow-same-version

- name: Commit and tag release version
id: release-ref
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

if ! git diff --quiet -- package.json package-lock.json; then
git add package.json package-lock.json
git commit -m "chore: release $RELEASE_VERSION"
fi

git tag "$RELEASE_VERSION"
git push origin "HEAD:${{ github.ref_name }}"
git push origin "$RELEASE_VERSION"
echo "release_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"

release:
needs: prepare-release
strategy:
matrix:
include:
Expand All @@ -19,15 +81,19 @@ jobs:
platform: mac

runs-on: ${{ matrix.os }}
env:
RELEASE_VERSION: ${{ needs.prepare-release.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare-release.outputs.release_sha }}

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: npm

- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"publish": {
"provider": "github",
"owner": "0suu",
"repo": "SwitchBotController"
"repo": "SwitchBotController",
"vPrefixedTagName": false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

タグ名から v プレフィックスを削除(vPrefixedTagName: false)すると、GitHub Actions などのワークフローでタグのプッシュをトリガーにしている場合(例: on: push: tags: - 'v*')、トリガー条件に一致しなくなり自動化が停止する可能性があります。リリース自動化を維持するためには、ワークフロー側のトリガー条件も更新する必要があります。

},
"files": [
"dist_electron/**/*",
Expand Down
Loading