-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (108 loc) · 3.49 KB
/
Copy pathpublish.yml
File metadata and controls
126 lines (108 loc) · 3.49 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
name: Publish to npm
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
build:
name: Build distribution
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Get version from package.json
id: get_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "📦 Version: $VERSION"
- name: Create and push tag
if: github.event_name == 'workflow_dispatch'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Only create tag if it doesn't exist
if ! git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}"
git push origin "v${{ steps.get_version.outputs.version }}"
echo "✅ Created and pushed tag v${{ steps.get_version.outputs.version }}"
else
echo "ℹ️ Tag v${{ steps.get_version.outputs.version }} already exists, skipping"
fi
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build package
run: npm run build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: npm-package-distributions
path: dist/
publish:
name: Publish to npm
needs: [build]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
environment:
name: npm
url: https://www.npmjs.com/package/agi
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: npm-package-distributions
path: dist/
- name: Publish to npm
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
create-release:
name: Create GitHub Release
needs: [build, publish]
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Extract changelog
id: changelog
run: |
VERSION="${{ needs.build.outputs.version }}"
# Extract the relevant section from CHANGELOG.md
BODY=$(awk "/## \[$VERSION\]/,/## \[/" CHANGELOG.md | sed '1d;$d')
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build.outputs.version }}
name: v${{ needs.build.outputs.version }}
body: ${{ steps.changelog.outputs.body }}
draft: false
prerelease: false