Repository navigation
98 lines (94 loc) · 3.76 KB
/
Copy pathrelease-github.yml
File metadata and controls
98 lines (94 loc) · 3.76 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
name: 'release: github'
run-name: 'release: github'
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
release:
description: Publish the GitHub release. The default is a dry run.
type: boolean
default: false
tag:
description: Existing registry version tag.
type: string
required: true
permissions:
contents: read
concurrency:
group: github-release-${{ github.repository }}
cancel-in-progress: false
jobs:
github-release:
name: Publish GitHub release
if: github.event_name == 'push' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Check out the workflow revision
shell: bash
env:
CHECKOUT_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
git init --quiet
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
auth="$(printf 'x-access-token:%s' "$CHECKOUT_TOKEN" | base64 -w0)"
echo "::add-mask::$auth"
GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0="http.$GITHUB_SERVER_URL/.extraheader" \
GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $auth" \
git fetch --quiet --tags origin "$GITHUB_SHA"
git checkout --quiet --detach FETCH_HEAD
- name: Validate the registry tag
id: tag
env:
INPUT_TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
TAG="${INPUT_TAG:-$GITHUB_REF_NAME}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Expected a registry version tag." >&2
exit 1
fi
git rev-parse --verify "refs/tags/$TAG^{commit}" >/dev/null
VERSION="$(git show "refs/tags/$TAG:registry/package.json" |
node -e 'process.stdout.write(JSON.parse(require("node:fs").readFileSync(0, "utf8")).version)')"
if [[ "$TAG" != "v$VERSION" ]]; then
echo "::error::The tag must match the version in registry/package.json." >&2
exit 1
fi
printf 'tag=%s\nversion=%s\n' "$TAG" "$VERSION" >> "$GITHUB_OUTPUT"
- name: Print release plan
if: github.event_name == 'workflow_dispatch' && !inputs.release
env:
TAG: ${{ steps.tag.outputs.tag }}
run: printf 'Dry run. Would publish GitHub release %s.\n' "$TAG"
- name: Require npm publication before releasing
if: github.event_name == 'push' || inputs.release
env:
VERSION: ${{ steps.tag.outputs.version }}
run: |
cd "$RUNNER_TEMP"
test "$(npm view "@socketsecurity/registry@$VERSION" version --registry https://registry.npmjs.org)" = "$VERSION"
- name: Publish GitHub release
if: github.event_name == 'push' || inputs.release
env:
CLIENT_ID: ${{ secrets.SOCKET_RELEASE_CLIENT_ID || vars.SOCKET_RELEASE_CLIENT_ID }}
APP_PRIVATE_KEY: ${{ secrets.SOCKET_RELEASE_APP_PRIVATE_KEY }}
TAG: ${{ steps.tag.outputs.tag }}
run: |
set -euo pipefail
GH_TOKEN="$(node scripts/ci/mint-release-token.mjs)"
unset APP_PRIVATE_KEY CLIENT_ID
echo "::add-mask::$GH_TOKEN"
export GH_TOKEN
trap 'gh api --method DELETE /installation/token --silent || true' EXIT
if ! gh release view "$TAG" --json isDraft >/dev/null 2>&1; then
args=(--draft --verify-tag --generate-notes)
if [[ "$TAG" == *-* ]]; then args+=(--prerelease); fi
gh release create "$TAG" "${args[@]}"
fi
if [[ "$(gh release view "$TAG" --json isDraft --jq .isDraft)" == true ]]; then
gh release edit "$TAG" --draft=false
fi