-
Notifications
You must be signed in to change notification settings - Fork 1
86 lines (76 loc) · 2.79 KB
/
CD.yml
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
name: CD
on:
workflow_run:
workflows: ['CI']
types:
- completed
jobs:
deploy:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
steps:
- name: Checkout and pnpm
uses: actions/[email protected]
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: '20.x'
cache: pnpm
cache-dependency-path: './pnpm-lock.yaml'
- name: Install Dependencies
run: pnpm i
- name: Build
run: pnpm freshBuild
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Configure npm for GitHub Packages
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
echo "@wojtekkrol:registry=https://npm.pkg.github.com" >> ~/.npmrc
- name: Insert repository owner as scope into package name
run: |
cp package.json package.json.bak
node <<EOF
const fs = require('fs').promises;
fs.readFile('package.json', 'utf8').then((data) => JSON.parse(data)).then((json) => {
json.name = '@' + process.env.GITHUB_REPOSITORY.split('/')[0].toLowerCase() + '/' + json.name;
console.info('Package name changed to %s', json.name);
return fs.writeFile('package.json', JSON.stringify(json, null, 2), 'utf8');
}).catch(error => {
console.error(error);
process.exit(1);
});
EOF
env:
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Insert repository owner as scope into package name
run: |
cp package.json package.json.bak
node <<EOF
const fs = require('fs').promises;
fs.readFile('package.json', 'utf8').then((data) => JSON.parse(data)).then((json) => {
json.name = '@' + process.env.GITHUB_REPOSITORY.split('/')[0] + '/' + json.name;
console.info('Package name changed to %s', json.name);
return fs.writeFile('package.json', JSON.stringify(json, null, 2), 'utf8');
}).catch(error => {
console.error(error);
process.exit(1);
});
EOF
env:
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Publish to GitHub Packages
run: pnpm publish --registry=https://npm.pkg.github.com/ --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Revert package.json
run: mv package.json.bak package.json
- name: Publish to npm
run: pnpm publish:npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}