-
-
Notifications
You must be signed in to change notification settings - Fork 1
121 lines (100 loc) · 3.83 KB
/
publish.yml
File metadata and controls
121 lines (100 loc) · 3.83 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
name: Publish to npm
on:
push:
branches:
- main
paths:
- 'package.json'
- '!.changeset/**'
permissions: read-all
jobs:
check-version:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check.outputs.changed }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 2
- name: Check if package.json version changed
id: check
run: |
CURRENT_VERSION=$(jq -r .version package.json)
PREVIOUS_VERSION=$(git show HEAD^:package.json | jq -r .version)
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
publish:
name: Build & Publish
needs: check-version
if: needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
attestations: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Run tests
run: npm run test:ci
- name: Setup Node.js for publish
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
run: npm publish --provenance --access public
- name: Get package info
id: package
run: |
VERSION=$(jq -r .version package.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.package.outputs.version }}" -m "Release v${{ steps.package.outputs.version }}"
git push origin "v${{ steps.package.outputs.version }}"
- name: Create GitHub Release
id: release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
with:
tag_name: v${{ steps.package.outputs.version }}
generate_release_notes: true
- name: Generate SBOM
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0
with:
format: spdx-json
output-file: sbom.spdx.json
upload-release-assets: false
upload-artifact: false
- name: Upload SBOM to release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
with:
tag_name: v${{ steps.package.outputs.version }}
files: sbom.spdx.json
- name: Announce release to Discord
run: |
TAG="v${{ steps.package.outputs.version }}"
VERSION="${{ steps.package.outputs.version }}"
NOTES=$(sed -n "/^## $VERSION$/,/^## /{ /^## /!p }" CHANGELOG.md | sed '/^[[:space:]]*$/d')
if [ -z "$NOTES" ]; then
NOTES="(no changelog entry found for $TAG)"
fi
PAYLOAD=$(jq -Rn --arg tag "$TAG" --arg repo "${{ github.repository }}" --arg notes "$NOTES" \
'{content: ("**New fetch-kit Release**\nRepository: \($repo) - version: \($tag)\n```\n\($notes)\n```")}')
curl -sS -H "Content-Type: application/json" -X POST -d "$PAYLOAD" ${{ secrets.DISCORD_WEBHOOK }}