-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (119 loc) · 3.45 KB
/
publish-package.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
name: Publish new package
on:
workflow_dispatch:
env:
PACKAGE_PREFIX: scottlogic-tech-carbon-estimator-
concurrency:
group: 'publish'
cancel-in-progress: false
jobs:
check_version:
runs-on: ubuntu-latest
outputs:
package_name: ${{ steps.output.outputs.package_name}}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Check that package version and tag align
run: |
VERSION=$(npm pkg get version --workspaces=false | tr -d \")
if [ ${GITHUB_REF_NAME} == v${VERSION} ]
then
echo "PACKAGE_NAME=${PACKAGE_PREFIX}${VERSION}" >> $GITHUB_ENV
else
echo "::error::Workflow must be run from tag that matches package version.%0A\
GITHUB_REF_NAME='${GITHUB_REF_NAME}', PACKAGE_VERSION='v${VERSION}'"
exit 1
fi
- name: Output package name
id: output
run: echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
test:
needs: check_version
uses: ./.github/workflows/buildAndTest.yml
package:
runs-on: ubuntu-latest
needs:
- check_version
- test
env:
PACKAGE_NAME: ${{needs.check_version.outputs.package_name}}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up environment
uses: ./.github/actions/set-up-environment
- name: Create package
run: |
npm run prepare
cp README.md package.json ./dist/tech-carbon-estimator/
cd dist/tech-carbon-estimator
npm pkg delete scripts private devDependencies files
npm pkg set main=main.js
npm pack
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: ${{env.PACKAGE_NAME}}
path: ./dist/tech-carbon-estimator/${{env.PACKAGE_NAME}}.tgz
publish:
runs-on: ubuntu-latest
needs:
- check_version
- package
env:
PACKAGE_NAME: ${{needs.check_version.outputs.package_name}}
permissions:
id-token: write
steps:
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- name: Download package
uses: actions/download-artifact@v4
with:
name: ${{env.PACKAGE_NAME}}
- name: Publish to NPM registry
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: |
npm publish ${PACKAGE_NAME}.tgz --provenance --access public
release:
runs-on: ubuntu-latest
needs:
- check_version
- package
- publish
env:
PACKAGE_NAME: ${{needs.check_version.outputs.package_name}}
permissions:
contents: write
steps:
- name: Download package
uses: actions/download-artifact@v4
with:
name: ${{env.PACKAGE_NAME}}
- name: Create Github Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${GITHUB_REF_NAME}" \
${PACKAGE_NAME}.tgz \
--repo="$GITHUB_REPOSITORY" \
--prerelease \
--verify-tag \
--generate-notes
publish_pages:
needs: release
permissions:
pages: write
id-token: write
contents: read
uses: ./.github/workflows/shared-pages.yml