-
Notifications
You must be signed in to change notification settings - Fork 2
137 lines (123 loc) Β· 4.72 KB
/
pkg-npm-publish.yaml
File metadata and controls
137 lines (123 loc) Β· 4.72 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
129
130
131
132
133
134
135
136
137
name: 'pkgs: Publish to npm registry'
run-name: 'Publish to npm registry (${{ inputs.version }})'
on:
workflow_dispatch:
inputs:
version:
description: 'Semantic Version'
required: true
default: 'minor'
type: choice
options:
- patch
- minor
- major
- prerelease
jobs:
publish:
name: 'Publish to npm registry'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: 'π Checkout Code'
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_BOT_TOKEN }}
- name: "π€ Enable Corepack"
run: corepack enable
- name: 'π’ Setup Node.js'
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://npm.pkg.github.com'
token: ${{ secrets.GH_BOT_TOKEN }}
scope: '@joggrdocs'
cache: 'yarn'
- name: 'π¦ Install packages'
run: yarn install
- name: 'πΌ Increment Version'
# We have to run with npm because yarn's update is based on "stableVersion" which is not what we want
run: yarn workspaces foreach --all exec npm version --no-git-tag-version --no-workspaces-update ${{ inputs.version }}
- name: '#οΈβ£ Get Version'
uses: actions/github-script@v8
id: version
with:
result-encoding: string
retries: 3
script: |
const fs = require('fs');
const pj = JSON.parse(fs.readFileSync('${{ github.workspace }}/package.json'));
return pj.version;
- name: 'ποΈ Build'
run: yarn turbo run build --filter="./packages/*"
- name: 'π§Ά Setup .yarnrc.yml'
run: |
yarn config set npmScopes.joggr.npmRegistryServer "https://registry.npmjs.org"
yarn config set npmScopes.joggr.npmAlwaysAuth true
yarn config set npmScopes.joggr.npmAuthToken $NPM_AUTH_TOKEN
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH }}
- name: 'π’ Publish'
run: yarn workspaces foreach -A --include "packages/*" npm publish --tolerate-republish --access public
- name: 'πΎ Commit Incremented Version'
run: |
git config --local user.email "${{ secrets.GH_BOT_EMAIL }}"
git config --local user.name "${{ secrets.GH_BOT_NAME }}"
git add ./packages/*/package.json ./package.json
git commit -m "[π€ npm-publish]: ${{ steps.version.outputs.result }} (${{ inputs.version }}) [skip-ci]"
git push origin HEAD --force
- name: 'π Publish Release Notes'
uses: release-drafter/release-drafter@v6
id: release_notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: v${{ steps.version.outputs.result }}
publish: true
- name: 'πͺ Send Slack Notification - Success'
uses: slackapi/slack-github-action@v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_RELEASE_BOT_TOKEN }}
payload: |
channel: ${{ vars.SLACK_RELEASE_CHANNEL_ID }}
text: "π¦ Published to npm: @joggr/tempo (${{ inputs.version }})"
blocks:
- type: header
text:
type: plain_text
text: "π¦ @joggr/tempo (${{ inputs.version }})"
- type: section
text:
type: mrkdwn
text: "Successfully published to npm registry (${{ inputs.version }}) workflow."
- type: divider
- type: actions
elements:
- type: button
text: 'View Release'
url: ${{ steps.release_notes.outputs.html_url }}
- name: 'πͺ Send Slack Notification - Failure'
uses: slackapi/slack-github-action@v2.0.0
if: ${{ failure() }}
with:
method: chat.postMessage
token: ${{ secrets.SLACK_RELEASE_BOT_TOKEN }}
payload: |
channel: ${{ vars.SLACK_RELEASE_CHANNEL_ID }}
text: "β Failed to publish to npm: @joggr/tempo (${{ inputs.version }})"
blocks:
- type: header
text:
type: plain_text
text: "@joggr/tempo (${{ inputs.version }})"
- type: section
text:
type: mrkdwn
text: "Failed to publish to npm"
- type: divider
- type: actions
elements:
- type: button
text: 'View Workflow Logs'
url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}