-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (160 loc) · 6.3 KB
/
release.yml
File metadata and controls
185 lines (160 loc) · 6.3 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Release
on:
push:
tags:
- "v*"
branches:
- main
workflow_dispatch:
permissions:
contents: write
jobs:
version-check:
name: Version check
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
tag: ${{ steps.check.outputs.tag }}
should_build: ${{ steps.check.outputs.should_build }}
should_release: ${{ steps.check.outputs.should_release }}
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 20
- name: Check version
id: check
run: |
set -euo pipefail
SHOULD_BUILD="true"
SHOULD_RELEASE="true"
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
TAG_NAME="${GITHUB_REF_NAME}"
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="$(node -p "require('./package.json').version")"
TAG_NAME="v${VERSION}"
fi
if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_TYPE}" != "tag" ]]; then
BEFORE_SHA="$(node -p "require(process.env.GITHUB_EVENT_PATH).before")"
if [[ -n "${BEFORE_SHA}" && "${BEFORE_SHA}" != "0000000000000000000000000000000000000000" ]]; then
if git show "${BEFORE_SHA}:package.json" >/dev/null 2>&1; then
PREV_VERSION="$(git show "${BEFORE_SHA}:package.json" | node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync(0,'utf8')); console.log(pkg.version||'');")"
if [[ "${PREV_VERSION}" == "${VERSION}" ]]; then
SHOULD_BUILD="false"
SHOULD_RELEASE="false"
fi
fi
fi
fi
if [[ "${GITHUB_REF_TYPE}" != "tag" ]]; then
if git show-ref --tags --quiet "refs/tags/${TAG_NAME}"; then
SHOULD_RELEASE="false"
fi
fi
if [[ "${SHOULD_BUILD}" != "true" ]]; then
SHOULD_RELEASE="false"
fi
{
echo "version=${VERSION}"
echo "tag=${TAG_NAME}"
echo "should_build=${SHOULD_BUILD}"
echo "should_release=${SHOULD_RELEASE}"
} >> "$GITHUB_OUTPUT"
build:
name: Build (${{ matrix.os }})
needs: version-check
if: needs.version-check.outputs.should_build == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
artifact_name: release-macos
artifact_path: release/*.dmg
- os: windows-latest
artifact_name: release-windows
artifact_path: release/*.exe
- os: ubuntu-latest
artifact_name: release-linux
artifact_path: release/*.AppImage
env:
CSC_IDENTITY_AUTO_DISCOVERY: "false"
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build release
run: npm run dist -- --publish=never
- name: Upload artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_path }}
if-no-files-found: error
release:
name: Create Release
runs-on: ubuntu-latest
needs: [version-check, build]
if: needs.version-check.outputs.should_release == 'true'
steps:
- name: Download artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
path: release-artifacts
- name: Compute SHA256 for macOS DMGs
id: dmg_shas
run: |
set -euo pipefail
MAC_DIR="release-artifacts/release-macos"
ARM_DMG="$(find "$MAC_DIR" -maxdepth 1 -type f -name '*-arm64.dmg' -print -quit)"
INTEL_DMG="$(find "$MAC_DIR" -maxdepth 1 -type f -name '*-x64.dmg' -print -quit)"
[[ -f "$ARM_DMG" ]] || { echo "arm64 dmg not found in $MAC_DIR"; ls -la "$MAC_DIR"; exit 1; }
[[ -f "$INTEL_DMG" ]] || { echo "x64 dmg not found in $MAC_DIR"; ls -la "$MAC_DIR"; exit 1; }
echo "ARM_SHA=$(sha256sum "$ARM_DMG" | awk '{print $1}')" >> "$GITHUB_OUTPUT"
echo "INTEL_SHA=$(sha256sum "$INTEL_DMG" | awk '{print $1}')" >> "$GITHUB_OUTPUT"
- name: Publish release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
with:
tag_name: ${{ needs.version-check.outputs.tag }}
name: API Key Health Checker ${{ needs.version-check.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
files: |
release-artifacts/**/*.dmg
release-artifacts/**/*.exe
release-artifacts/**/*.AppImage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Homebrew tap
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
repository: nbox/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Update cask in tap repo
run: |
set -euo pipefail
VERSION="${{ needs.version-check.outputs.version }}"
ARM_SHA="${{ steps.dmg_shas.outputs.ARM_SHA }}"
INTEL_SHA="${{ steps.dmg_shas.outputs.INTEL_SHA }}"
CASK="tap/Casks/api-key-health-checker.rb"
perl -i -pe 's/^ version ".*"$/ version "'"$VERSION"'"/' "$CASK"
perl -0777 -i -pe 's/sha256 arm:\s*".*?",\s*\n\s*intel:\s*".*?"/sha256 arm: "'"$ARM_SHA"'",\n intel: "'"$INTEL_SHA"'"/s' "$CASK"
git -C tap config user.name "github-actions[bot]"
git -C tap config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C tap add Casks/api-key-health-checker.rb
git -C tap commit -m "api-key-health-checker $VERSION" || exit 0
git -C tap push