160 lines (131 loc) · 4.95 KB
/
productionize.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
#/
# @license Apache-2.0
#
# Copyright (c) 2022 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: productionize
# Workflow triggers:
on:
# Run workflow when a new commit is pushed to the repository:
push:
# Allow the workflow to be manually run:
workflow_dispatch:
# Workflow jobs:
jobs:
# Define a job to create a production build...
productionize:
# Define display name:
name: 'Productionize'
# Define the type of virtual host machine:
runs-on: 'ubuntu-latest'
# Define the sequence of job steps...
steps:
# Checkout main branch of repository:
- name: 'Checkout main branch'
uses: actions/checkout@v3
with:
ref: main
# Install Node.js:
- name: 'Install Node.js'
uses: actions/setup-node@v2
with:
node-version: 16
timeout-minutes: 5
# Create production branch:
- name: 'Create production branch'
run: |
git checkout -b production
# Transform error messages:
- name: 'Transform error messages'
id: transform-error-messages
uses: stdlib-js/transform-errors-action@main
# Format error messages:
- name: 'Replace double quotes with single quotes in rewritten format string error messages'
run: |
find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \;
# Format string literal error messages:
- name: 'Replace double quotes with single quotes in rewritten string literal error messages'
run: |
find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \;
# Format code:
- name: 'Replace double quotes with single quotes in inserted `require` calls'
run: |
find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \;
# Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency:
- name: 'Update dependencies in package.json'
run: |
if grep -q '"@stdlib/string-format"' package.json; then
sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json
else
node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );"
fi
# Configure git:
- name: 'Configure git'
run: |
git config --local user.email "noreply@stdlib.io"
git config --local user.name "stdlib-bot"
# Commit changes:
- name: 'Commit changes'
run: |
git add -A
git commit -m "Transform error messages"
# Push changes:
- name: 'Push changes'
run: |
SLUG=${{ github.repository }}
echo "Pushing changes to $SLUG..."
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force
# Define a job for running tests of the productionized code...
test:
# Define a display name:
name: 'Run Tests'
# Define the type of virtual host machine:
runs-on: 'ubuntu-latest'
# Indicate that this job depends on the prior job finishing:
needs: test
# Run this job regardless of the outcome of the prior job:
if: always()
# Define the sequence of job steps...
steps:
# Checkout the repository:
- name: 'Checkout repository'
uses: actions/checkout@v3
with:
# Use the `production` branch:
ref: production
# Install Node.js:
- name: 'Install Node.js'
uses: actions/setup-node@v2
with:
node-version: 16
timeout-minutes: 5
# Install dependencies:
- name: 'Install production and development dependencies'
id: install
run: |
npm install || npm install || npm install
timeout-minutes: 15
# Build native add-on if present:
- name: 'Build native add-on (if present)'
run: |
if [ -f "binding.gyp" ]; then
npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild
fi
# Run tests:
- name: 'Run tests'
id: tests
run: |
npm test || npm test || npm test