Repository navigation
136 lines (123 loc) · 4.3 KB
/
Copy pathnode-release.yml
File metadata and controls
136 lines (123 loc) · 4.3 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
name: Node Release
on:
workflow_call:
inputs:
node-version:
type: string
required: true
build-script:
type: string
default: 'build'
publish-command:
type: string
default: 'npm publish "$PACKAGE" --access public'
registry-url:
type: string
default: 'https://registry.npmjs.org'
create-release:
type: boolean
default: true
secrets:
MATRIX_ACCESS_TOKEN:
required: false
jobs:
# installs and builds without the permission to publish, a compromised dependency cannot publish
build:
runs-on: ubuntu-latest
# a poisoned node_modules from the cache would end up in the published package
cache-mode: none
permissions:
contents: read
steps:
- name: Check tag
if: github.ref_type != 'tag'
run: |
echo "::error::node-release must run on a tag, not on ${GITHUB_REF}"
exit 1
- uses: $/.github/actions/node-setup
with:
node-version: ${{ inputs.node-version }}
- name: Build
if: inputs.build-script != ''
env:
BUILD_SCRIPT: ${{ inputs.build-script }}
run: yarn run "$BUILD_SCRIPT"
- name: Pack
run: |
if [[ "$(yarn --version)" == 1.* ]]; then
yarn pack --filename "${RUNNER_TEMP}/package.tgz"
else
yarn pack --out "${RUNNER_TEMP}/package.tgz"
fi
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package
path: ${{ runner.temp }}/package.tgz
if-no-files-found: error
retention-days: 1
# runs no code of the dependencies, it publishes the package packed by the build job
publish:
needs: build
runs-on: ubuntu-latest
cache-mode: none
permissions:
contents: write
id-token: write
outputs:
published: ${{ steps.publish.outcome }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: package
path: ${{ runner.temp }}/package
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ inputs.node-version }}
registry-url: ${{ inputs.registry-url }}
- name: Publish
id: publish
env:
PUBLISH_COMMAND: ${{ inputs.publish-command }}
PACKAGE: ${{ runner.temp }}/package/package.tgz
run: eval "$PUBLISH_COMMAND"
- name: Create GitHub release
if: inputs.create-release
uses: $/.github/actions/github-release
with:
tag: ${{ github.ref_name }}
notify:
needs: [build, publish]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Compose the notification
id: notification
env:
REPOSITORY: ${{ github.repository }}
TAG: ${{ github.ref_name }}
RESULT: ${{ needs.publish.result }}
PUBLISHED: ${{ needs.publish.outputs.published }}
LINK: ${{ inputs.create-release && format('{0}/{1}/releases/tag/{2}', github.server_url, github.repository, github.ref_name) || format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ "$RESULT" = success ]; then
MESSAGE="✅ ${REPOSITORY} ${TAG} published: ${LINK}"
elif [ "$PUBLISHED" = success ]; then
MESSAGE="⚠️ ${REPOSITORY} ${TAG} published, but the GitHub release failed: ${RUN_URL}"
else
MESSAGE="❌ Publishing ${TAG} of ${REPOSITORY} failed: ${RUN_URL}"
fi
echo "message=${MESSAGE}" >> "$GITHUB_OUTPUT"
- name: Notify Matrix
continue-on-error: true
uses: $/.github/actions/matrix-notify
with:
message: ${{ steps.notification.outputs.message }}
homeserver: ${{ vars.MATRIX_HOMESERVER }}
room-id: ${{ vars.MATRIX_ROOM_ID }}
token: ${{ secrets.MATRIX_ACCESS_TOKEN }}