-
Notifications
You must be signed in to change notification settings - Fork 1
111 lines (93 loc) · 3.09 KB
/
Copy pathrelease.yml
File metadata and controls
111 lines (93 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Build & Release
on:
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:
- os: windows-latest
platform: win
- os: macos-latest
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: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build application
run: npm run build
- name: Package & publish to GitHub Releases
run: npx electron-builder --${{ matrix.platform }} --publish always
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}