forked from qld-gov-au/qgds-bootstrap5
-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (151 loc) · 5.67 KB
/
githubPackage.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
171
172
173
174
175
176
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Publish NPM Github Package store
on:
push:
#On versioned releases
tags:
- v*.*.*
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
force:
type: choice
description: Retry Publish Version
options:
- No
- Yes
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '20' ]
name: Lint, Test, Build and Deploy on Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v4.1.2
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Use Node.js
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ matrix.node }}
cache: 'npm'
#always-auth: 'true'
#registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/'
registry-url: 'https://registry.npmjs.org'
- name: Install #run on lint step (Which is cached)
run: | # Install packages per package-lock.json only
npm ci
- name: Lint
run: |
npm run lint
- name: Test
run: |
npm run test
- name: Build 🔧
run: | # build the files
npm run build
# - name: Build storybook 🔧
# run: | # build the Storybook files
# npm run build-storybook
publish-gpr:
needs: build
env:
#When run on push tags, force is '', default for workflow_dispatch is No so you can't trigger without a double action
DO_DEPLOYMENT: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.force == 'Yes' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
# Defaults to the user or organization that owns the workflow file
#scope: '@${username:lowercase}'
cache: 'npm'
- name: npm config output (including .npmrc file)
run: |
npm -v
node -v
cat /home/runner/work/_temp/.npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: npm ci
- name: Build 🔧
run: | # build the files
npm run build
- name: "Update package scope, export package name"
id: package_details
run: |
echo "replacing npm scope to repo owner GITHUB_REPOSITORY_OWNER = $GITHUB_REPOSITORY_OWNER"
temp_file=$(mktemp)
package=${GITHUB_REPOSITORY_OWNER,,}
awk -v scope="$package" '{
if ($0 ~ /"name": "@[a-zA-Z0-9_-]+\//) {
sub(/@[a-zA-Z0-9_-]+\//, "@" scope "/")
}
print
}' package.json > "$temp_file" && mv "$temp_file" package.json
echo "package.json updated"
cat package.json
echo "package=`npm pkg get name`" >> $GITHUB_STATE
- uses: tobysmith568/npm-publish-latest-tag@v1
id: latest_tag
with:
package-json: ./package.json
# - uses: actions/delete-package-versions@v5
# with: #Delete all except latest 3 package versions excluding major versions as per semver from a repo not having access to package
## owner: 'github'
# package-name: ${{ steps.package_details.outputs.package }}
# package-type: 'npm'
## token: ${{ secrets.GITHUB_PAT }}
# min-versions-to-keep: 3
# ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
# env:
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Publish
run: npm publish --tag ${{ steps.latest_tag.outputs.latest-tag }}
if: ${{ env.DO_DEPLOYMENT == 'true' }}
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Publish - Skipped
if: ${{ env.DO_DEPLOYMENT != 'true' }}
run: |
echo "### Publish skipped" >> $GITHUB_STEP_SUMMARY
echo "DO_DEPLOYMENT( ${{ env.DO_DEPLOYMENT }} ): github.event_name: ${{ github.event_name != 'workflow_dispatch'}} || github.event.inputs.force: ${{ github.event.inputs.force == 'Yes' }}" >> $GITHUB_STEP_SUMMARY