Repository navigation
91 lines (87 loc) · 4 KB
/
Copy pathrelease-github.yml
File metadata and controls
91 lines (87 loc) · 4 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
name: GitHub release
run-name: GitHub release
on:
workflow_dispatch:
inputs:
tag:
description: Existing version tag to finalize after npm publication
required: true
type: string
permissions:
contents: read
concurrency:
group: github-release-${{ github.repository }}-${{ inputs.tag }}
cancel-in-progress: false
jobs:
release:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-26.04
timeout-minutes: 35
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0
persist-credentials: false
- name: Verify existing release tag
id: release
env:
GH_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
TAG: ${{ inputs.tag }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
if ! [[ "${TAG}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$ ]]; then
echo '::error::Tag is not a safe version tag.'
exit 1
fi
VERSION="${TAG#v}"
test "$(node -p "require('./package.json').name")" = '@socketsecurity/mcp'
TAG_MANIFEST="$(git show "refs/tags/${TAG}:package.json")"
TAG_NAME="$(node -e 'process.stdout.write(JSON.parse(require("node:fs").readFileSync(0, "utf8")).name)' <<<"${TAG_MANIFEST}")"
TAG_VERSION="$(node -e 'process.stdout.write(JSON.parse(require("node:fs").readFileSync(0, "utf8")).version)' <<<"${TAG_MANIFEST}")"
test "${TAG_NAME}" = '@socketsecurity/mcp'
test "${TAG_VERSION}" = "${VERSION}"
TAG_SHA="$(git rev-parse --verify "refs/tags/${TAG}^{commit}")"
test "$(gh api "repos/${GITHUB_REPOSITORY}/commits/${TAG_SHA}" --jq '.commit.verification.verified')" = true
git merge-base --is-ancestor "${TAG_SHA}" "origin/${DEFAULT_BRANCH}"
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version-file: .node-version
# npm lifecycle: validating waits; staged is approved locally with 2FA;
# published becomes available; blocked or deleted versions stop. An
# anonymous HEAD 404 cannot distinguish pending, blocked, deleted, or
# missing versions. A timeout preserves the version for retry.
- name: Wait for exact npm version
run: node scripts/npm/availability.mts "${VERSION}"
env:
VERSION: ${{ steps.release.outputs.version }}
- name: Create or finish GitHub release
env:
GH_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
TAG: ${{ steps.release.outputs.tag }}
VERSION: ${{ steps.release.outputs.version }}
run: |
set -euo pipefail
IS_PRERELEASE=false
if [[ "$VERSION" == *-* ]]; then
IS_PRERELEASE=true
fi
if ! gh release view "${TAG}" >/dev/null 2>&1; then
git show "refs/tags/${TAG}:CHANGELOG.md" | awk -v version="${TAG#v}" 'index($0, "## [" version "]") == 1 { found=1; print; next } found && /^## / { exit } found { print }' > release-notes.md
test -s release-notes.md
if [[ "$IS_PRERELEASE" == true ]]; then
gh release create "${TAG}" --draft --verify-tag --notes-file release-notes.md --prerelease
else
gh release create "${TAG}" --draft --verify-tag --notes-file release-notes.md
fi
fi
RELEASE_ID=$(gh release view "${TAG}" --json databaseId --jq '.databaseId')
gh api "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" -X PATCH \
-F draft=false -F prerelease="${IS_PRERELEASE}" >/dev/null