-
-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (143 loc) · 5.78 KB
/
publish_cli.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#/
# @license Apache-2.0
#
# Copyright (c) 2023 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# Workflow name:
name: publish_cli
# Workflow triggers:
on:
# Allow the workflow to be manually run:
workflow_dispatch:
# Workflow inputs:
inputs:
version:
description: 'Version Increment'
type: choice
default: 'none'
options:
- 'none'
- 'major'
- 'minor'
- 'patch'
- 'premajor'
- 'preminor'
- 'prepatch'
- 'prerelease'
# Workflow jobs:
jobs:
# Define job to publish package to npm:
publish:
# Define display name:
name: 'Publish CLI package to npm'
# Define the type of virtual host machine on which to run the job:
runs-on: ubuntu-latest
# Define environment variables:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# Define the sequence of job steps...
steps:
# Checkout cli branch:
- name: 'Checkout cli branch'
# Pin action to full length commit SHA
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
ref: cli
# Install Node.js:
- name: 'Install Node.js'
# Pin action to full length commit SHA
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: 20
timeout-minutes: 5
# Configure git:
- name: 'Configure git'
run: |
git config --local user.email "[email protected]"
git config --local user.name "stdlib-bot"
# Increment package version (if requested):
- name: 'Increment package version (if requested)'
if: ${{ github.event.inputs.version != 'none' }}
run: |
# Save NPM_TOKEN to user's .npmrc:
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
# Increment package version:
npm version ${{ github.event.inputs.version }} --no-git-tag-version
# Define variable for new version:
NEW_VERSION=$(node -p "require('./package.json').version")
# Replace branch in README.md link definitions for badges with the new version:
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/branch([=:])[^ ]+/branch\1v${NEW_VERSION}/g"
# Create a new commit and tag:
git add package.json README.md
git commit -m "Release v${NEW_VERSION}"
git tag -a "v${NEW_VERSION}-cli" -m "Release v${NEW_VERSION}"
# Push changes to GitHub:
SLUG=${{ github.repository }}
git push "https://$GITHUB_ACTOR:[email protected]/$SLUG.git" --follow-tags
# Replace GitHub MathJax equations with SVGs:
- name: 'Replace GitHub MathJax equations with SVGs'
run: |
find . -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe 's/```math\n([\s\S]+?)\n```\n\n//g'
find . -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe 's/<!-- <div class="equation"(.*)(<\/div>\s*-->)/<div class="equation"$1<\/div>/sg'
# Replace GitHub links to individual packages with npm links:
- name: 'Replace all GitHub links to individual packages with npm links'
run: |
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei '/tree\/main/b; s/@stdlib\/([^:]*)\]: https:\/\/github.com\/stdlib-js/@stdlib\/\1\]: https:\/\/www.npmjs.com\/package\/@stdlib/g'
SLUG=${{ github.repository }}
ESCAPED_SLUG=${SLUG//\//\\\/}
REPO=${SLUG#*/}
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/https:\/\/github.com\/${ESCAPED_SLUG}\/tree\/main/https:\/\/www.npmjs.com\/package\/@stdlib\/${REPO}/g"
# Publish package to npm:
- name: 'Publish package to npm'
# Pin action to full length commit SHA
uses: JS-DevTools/npm-publish@4b07b26a2f6e0a51846e1870223e545bae91c552 # v3.0.1
with:
token: ${{ secrets.NPM_TOKEN }}
access: public
# Discard any uncommitted changes:
- name: 'Discard any uncommitted changes'
run: |
git reset --hard
# Send status to Slack channel if job fails:
- name: 'Send status to Slack channel in case of failure'
# Pin action to full length commit SHA corresponding to v2.0.0
uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#npm-ci'
if: failure()
# Define job to cancel any running or queued workflow runs...
cancel:
# Define the type of virtual host machine on which to run the job:
runs-on: ubuntu-latest
# Time out the job after 3 minutes:
timeout-minutes: 3
# Define the sequence of job steps...
steps:
# Cancel any running or queued workflow runs:
- name: 'Cancel running or queued workflow runs'
# Pin action to full length commit SHA
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1
with:
workflow_id: >-
benchmark.yml,
examples.yml,
test.yml,
test_coverage.yml,
test_install.yml,
publish.yml
access_token: ${{ github.token }}