-
-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (114 loc) · 4.22 KB
/
Copy pathpublish-packages.yml
File metadata and controls
128 lines (114 loc) · 4.22 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
name: Publish Packages
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
publish_sdk:
description: 'Publish @levelcode/sdk'
required: true
default: true
type: boolean
publish_cli:
description: 'Publish @levelcode/cli'
required: true
default: true
type: boolean
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.2.x'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Set environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts --scope client 2>/dev/null || echo '[]')
if [ "$VAR_NAMES" != "[]" ]; then
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
fi
echo "NEXT_PUBLIC_CB_ENVIRONMENT=prod" >> $GITHUB_ENV
echo "LEVELCODE_GITHUB_ACTIONS=true" >> $GITHUB_ENV
- name: Bump SDK version
if: inputs.publish_sdk
run: |
cd sdk
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const parts = pkg.version.split('.');
if ('${{ inputs.version_type }}' === 'major') { parts[0]++; parts[1]=0; parts[2]=0; }
else if ('${{ inputs.version_type }}' === 'minor') { parts[1]++; parts[2]=0; }
else { parts[2]++; }
pkg.version = parts.join('.');
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
console.log('SDK version: ' + pkg.version);
"
- name: Bump CLI version
if: inputs.publish_cli
run: |
cd cli
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const parts = pkg.version.split('.');
if ('${{ inputs.version_type }}' === 'major') { parts[0]++; parts[1]=0; parts[2]=0; }
else if ('${{ inputs.version_type }}' === 'minor') { parts[1]++; parts[2]=0; }
else { parts[2]++; }
pkg.version = parts.join('.');
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
console.log('CLI version: ' + pkg.version);
"
- name: Build SDK
if: inputs.publish_sdk
run: cd sdk && bun run build
- name: Publish SDK
if: inputs.publish_sdk
run: cd sdk && npm publish --access public --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Prebuild agents and build CLI
if: inputs.publish_cli
run: |
cd cli
bun run prebuild:agents
rm -rf dist
bun build src/index.tsx --outdir dist --target bun
- name: Publish CLI
if: inputs.publish_cli
run: cd cli && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit and push version bumps
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add sdk/package.json cli/package.json
SDK_VERSION=$(node -e "console.log(require('./sdk/package.json').version)")
CLI_VERSION=$(node -e "console.log(require('./cli/package.json').version)")
git commit -m "chore: publish @levelcode/sdk@${SDK_VERSION} @levelcode/cli@${CLI_VERSION}" || echo "No changes to commit"
git push origin master