-
Notifications
You must be signed in to change notification settings - Fork 3.6k
93 lines (81 loc) · 2.88 KB
/
publish-cli.yml
File metadata and controls
93 lines (81 loc) · 2.88 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
name: Publish Sim Studio CLI
on:
push:
branches:
- main
paths:
- 'packages/simstudio/**'
- '.github/workflows/publish-cli.yml'
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: 'packages/simstudio/package-lock.json'
- name: Install dependencies
working-directory: packages/simstudio
run: npm ci
- name: Build package
working-directory: packages/simstudio
run: npm run build
- name: Get version
working-directory: packages/simstudio
id: get_version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Check version update
working-directory: packages/simstudio
run: |
if ! git diff ${{ github.event.before }} ${{ github.sha }} packages/simstudio/package.json | grep -q '"version":'; then
echo "::error::Version not updated in package.json"
exit 1
fi
- name: Run tests
working-directory: packages/simstudio
run: npm test
- name: Check for changes
working-directory: packages/simstudio
id: check_changes
run: |
if git diff --quiet ${{ github.event.before }} ${{ github.sha }} packages/simstudio/; then
echo "changes=false" >> $GITHUB_OUTPUT
else
echo "changes=true" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
if: steps.check_changes.outputs.changes == 'true'
working-directory: packages/simstudio
run: |
if ! npm publish; then
echo "::error::Failed to publish package"
exit 1
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Git tag
if: steps.check_changes.outputs.changes == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
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 }}"
- name: Create GitHub Release
if: steps.check_changes.outputs.changes == 'true'
uses: softprops/action-gh-release@v1
with:
name: "v${{ steps.get_version.outputs.version }}"
tag_name: "v${{ steps.get_version.outputs.version }}"
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}