forked from samclarke/SCEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (79 loc) · 3.1 KB
/
Copy pathrelease.yml
File metadata and controls
92 lines (79 loc) · 3.1 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
name: Release
on:
workflow_run:
workflows: ["build & test"]
types: [completed]
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'master'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Use Node.js
uses: actions/setup-node@v7
with:
node-version: latest
registry-url: "https://registry.npmjs.org"
cache: "npm"
# npm Trusted Publishing (OIDC) requires npm CLI 11.5.1+; make sure we have it
# regardless of whatever version setup-node's Node build happens to bundle.
- name: Ensure npm supports trusted publishing
run: npm install -g npm@latest
- name: Determine current and latest released version
id: version
env:
GH_TOKEN: ${{ github.token }}
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
LATEST_TAG=$(gh release view --json tagName -q .tagName --repo "$GITHUB_REPOSITORY" 2>/dev/null || echo "v0.0.0")
LATEST_VERSION=${LATEST_TAG#v}
IS_NEWER=$(node -e "
const gt = (a, b) => {
const pa = a.split('.').map(Number);
const pb = b.split('.').map(Number);
for (let i = 0; i < 3; i++) {
if ((pa[i] || 0) > (pb[i] || 0)) return true;
if ((pa[i] || 0) < (pb[i] || 0)) return false;
}
return false;
};
console.log(gt('$PKG_VERSION', '$LATEST_VERSION'));
")
echo "pkg_version=$PKG_VERSION" >> "$GITHUB_OUTPUT"
echo "latest_version=$LATEST_VERSION" >> "$GITHUB_OUTPUT"
echo "is_newer=$IS_NEWER" >> "$GITHUB_OUTPUT"
echo "package.json version: $PKG_VERSION / latest release: $LATEST_VERSION / newer: $IS_NEWER"
- name: Install dependencies
if: steps.version.outputs.is_newer == 'true'
run: npm ci
- name: Build
if: steps.version.outputs.is_newer == 'true'
run: npm run build
- name: Create GitHub release
if: steps.version.outputs.is_newer == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v${{ steps.version.outputs.pkg_version }}" \
--repo "$GITHUB_REPOSITORY" \
--target "${{ github.event.workflow_run.head_sha }}" \
--title "v${{ steps.version.outputs.pkg_version }}" \
--generate-notes
# Authenticates via OIDC using the job's id-token permission — no NPM_TOKEN secret needed.
# Requires the "@w8tcha/bootbox" package to have this repo + workflow registered as a
# Trusted Publisher in npm's package settings (see npmjs.com package Settings page).
- name: Publish to npm
if: steps.version.outputs.is_newer == 'true'
run: npm publish --access public