forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (167 loc) · 6.67 KB
/
publish-npm-packages.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
name: Publish Bento Packages on npm
on:
# to be triggered by ampproject/cdn-configuration promote workflows
workflow_call:
inputs:
amp-version:
description: 'AMP version'
required: true
type: string
tag:
description: 'npm package tag'
required: true
type: string
# to be run manually
workflow_dispatch:
inputs:
amp-version:
description: 'AMP version'
required: true
tag:
description: 'npm package tag'
required: true
type: choice
options:
- latest
- nightly
env:
SCRIPTS_REPO: 'https://raw.githubusercontent.com/ampproject/amphtml/main'
SCRIPTS_DIR: 'build-system/npm-publish'
permissions:
contents: read
jobs:
setup:
runs-on: ubuntu-latest
outputs:
extensions: ${{ steps.get-extensions.outputs.extensions }}
steps:
- name: Print inputs
run: |
echo "AMP version: ${{ github.event.inputs.amp-version }}"
echo "npm tag: ${{ github.event.inputs.tag }}"
- uses: actions/checkout@v2
with:
ref: ${{ github.events.inputs.amp-version }}
- name: Get latest scripts
run: wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/get-extensions.js" -O ${{ env.SCRIPTS_DIR }}/get-extensions.js
- name: Get extensions to publish
id: get-extensions
run: |
EXTENSIONS=$(node ${{ env.SCRIPTS_DIR }}/get-extensions.js)
echo "::set-output name=extensions::{\"include\":${EXTENSIONS}}"
publish-core:
if: github.repository == 'ampproject/amphtml'
environment: bento_publishing
needs: setup
runs-on: ubuntu-latest
outputs:
core-version: ${{ steps.build-core.outputs.core-version }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.events.inputs.amp-version }}
- uses: actions/setup-node@v2
with:
registry-url: https://registry.npmjs.org
node-version: lts/*
- name: Get latest scripts
run: |
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/utils.js" -O ${{ env.SCRIPTS_DIR }}/utils.js
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/get-core-version.js" -O ${{ env.SCRIPTS_DIR }}/get-core-version.js
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/build-npm-binaries.js" -O ${{ env.SCRIPTS_DIR }}/build-npm-binaries.js
- name: Build package
id: build-core
run: |
npm ci
node ${{ env.SCRIPTS_DIR }}/build-npm-binaries.js
CORE_VERSION=$(node ${{ env.SCRIPTS_DIR }}/get-core-version.js ${{ github.event.inputs.amp-version }})
cd ./src/bento/core
npm version $CORE_VERSION --git-tag-version=false --allow-same-version=true
echo "::set-output name=core-version::${CORE_VERSION}"
- name: Publish package for Nightly releases
if: github.event.inputs.tag != 'latest'
run: |
npm publish ./src/bento/core --access public --tag ${{ github.event.inputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tag package as latest for Stable releases
if: github.event.inputs.tag == 'latest'
run: |
NPM_PACKAGE=$(jq -r .name ./src/bento/core/package.json)
NPM_VERSION=$(jq -r .version ./src/bento/core/package.json)
echo "Processing ${NPM_PACKAGE}@${NPM_VERSION}"
if [[ $(npm view ${NPM_PACKAGE}@${NPM_VERSION}) ]]; then
npm dist-tag add ${NPM_PACKAGE}@${NPM_VERSION} latest
else
npm publish ./src/bento/core --access public --tag latest
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish:
if: github.repository == 'ampproject/amphtml'
environment: bento_publishing
needs: [setup, publish-core]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.setup.outputs.extensions) }}
fail-fast: false
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.events.inputs.amp-version }}
- uses: actions/setup-node@v2
with:
registry-url: https://registry.npmjs.org
node-version: lts/*
- name: Get latest scripts
run: |
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/utils.js" -O ${{ env.SCRIPTS_DIR }}/utils.js
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/build-npm-binaries.js" -O ${{ env.SCRIPTS_DIR }}/build-npm-binaries.js
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/get-package-dir.js" -O ${{ env.SCRIPTS_DIR }}/get-package-dir.js
wget -q "${{ env.SCRIPTS_REPO }}/${{ env.SCRIPTS_DIR }}/write-package-files.js" -O ${{ env.SCRIPTS_DIR }}/write-package-files.js
- name: Build package
run: |
npm ci
node ${{ env.SCRIPTS_DIR }}/build-npm-binaries.js ${{ matrix.extension }}
node ${{ env.SCRIPTS_DIR }}/write-package-files.js ${{ matrix.extension }} ${{ github.event.inputs.amp-version }} ${{ matrix.version }} ${{ needs.publish-core.outputs.core-version }}
- name: Publish package for Nightly releases
if: github.event.inputs.tag != 'latest'
run: |
cd $(node ${{ env.SCRIPTS_DIR }}/get-package-dir.js ${{ matrix.extension }} ${{ matrix.version }})
npm publish --access public --tag ${{ github.event.inputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tag package as latest for Stable releases
if: github.event.inputs.tag == 'latest'
run: |
cd $(node ${{ env.SCRIPTS_DIR }}/get-package-dir.js ${{ matrix.extension }} ${{ matrix.version }})
NPM_PACKAGE=$(jq -r .name package.json)
NPM_VERSION=$(jq -r .version package.json)
echo "Processing ${NPM_PACKAGE}@${NPM_VERSION}"
if [[ $(npm view ${NPM_PACKAGE}@${NPM_VERSION}) ]]; then
npm dist-tag add ${NPM_PACKAGE}@${NPM_VERSION} latest
else
npm publish --access public --tag latest
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
create-issue-on-error:
if: failure()
needs: publish
permissions:
contents: read
issues: write
runs-on: ubuntu-latest
environment: create_issue_on_error
steps:
- uses: actions/checkout@v3
- name: Create issue on error
uses: JasonEtco/create-an-issue@v2
with:
filename: .github/create_issue_on_error.md
env:
GITHUB_TOKEN: ${{ secrets.AMPPROJECTBOT }}
WORKFLOW_NAME: ${{ github.workflow }}
MENTION: '@ampproject/wg-infra'
REPO_SLUG: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}