-
Notifications
You must be signed in to change notification settings - Fork 85
104 lines (91 loc) · 4.15 KB
/
Copy pathrelease.yml
File metadata and controls
104 lines (91 loc) · 4.15 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
name: Publish SDK to NPM and GitHub Package Registry
on:
release:
types: [published, edited]
workflow_dispatch: {}
jobs:
publish:
name: Publish to NPM and GitHub Package Registry
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
permissions:
contents: read
packages: write
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org/"
always-auth: "true"
# Add auth for the GitHub Package Registry publish. npm expands
# ${NODE_AUTH_TOKEN} at runtime per-step, so each publish step uses the
# right token for its registry. We do NOT route the @optimizely scope to
# GPR, so `npm ci` still resolves dependencies from npm; publish.sh passes
# --registry explicitly to target GPR.
- name: Configure GitHub Package Registry auth
run: echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> ~/.npmrc
# Deps only. --ignore-scripts stops `prepare` from building here; we build
# exactly once in the pack step below.
- name: Install dependencies
run: npm ci --ignore-scripts
- id: latest-release
name: Export latest release git tag
run: |
echo "latest-release-tag=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_OUTPUT
- id: npm-tag
name: Determine NPM tag
env:
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
VERSION=$(jq -r '.version' package.json)
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/}
else
RELEASE_TAG=$GITHUB_RELEASE_TAG
fi
if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-beta"* ]]; then
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-alpha"* ]]; then
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-rc"* ]]; then
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
else
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
fi
# Test, build, and pack a single tarball. Both registries publish this
# same artifact, so npm and GPR receive byte-identical bytes and the test
# suite runs only once. --ignore-scripts on pack avoids a rebuild.
- id: pack
name: Test, build, and pack
run: |
npm test
npm run build
tarball=$(npm pack --ignore-scripts | tail -n1)
echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
- id: release
name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' }}
run: scripts/publish.sh "https://registry.npmjs.org" "${{ steps.pack.outputs.tarball }}" "${{ steps.npm-tag.outputs['npm-tag'] }}"
- name: Publish to GitHub Package Registry
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' }}
run: scripts/publish.sh "https://npm.pkg.github.com" "${{ steps.pack.outputs.tarball }}" "${{ steps.npm-tag.outputs['npm-tag'] }}"
# - name: Report results to Jellyfish
# uses: optimizely/jellyfish-deployment-reporter-action@main
# if: ${{ always() && github.event_name == 'release' && (steps.release.outcome == 'success' || steps.release.outcome == 'failure') }}
# with:
# jellyfish_api_token: ${{ secrets.JELLYFISH_API_TOKEN }}
# is_successful: ${{ steps.release.outcome == 'success' }}