-
Notifications
You must be signed in to change notification settings - Fork 43
85 lines (67 loc) · 3.08 KB
/
Copy pathnpm-publish.yml
File metadata and controls
85 lines (67 loc) · 3.08 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
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
name: Publish NPM on Release
on:
release:
types: [published]
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v7
with:
node-version-file: ./package.json
- run: npm ci
- run: npm test
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v7
with:
node-version-file: ./package.json
registry-url: https://registry.npmjs.org/
- run: npm publish
- name: Close release milestone if empty
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
set -euo pipefail
owner="${REPO%%/*}"
repo="${REPO##*/}"
milestone_title="${RELEASE_TAG#v}"
if [ -z "${milestone_title}" ]; then
echo "Could not parse milestone version from release tag (tag=${RELEASE_TAG})."
exit 0
fi
milestones_json="$(gh api "repos/${owner}/${repo}/milestones?state=open&per_page=100")"
milestone_number="$(echo "$milestones_json" | jq -r \
--arg milestone_title "$milestone_title" \
'.[] | select(.title == $milestone_title) | .number' \
| head -n1)"
if [ -z "${milestone_number}" ] || [ "${milestone_number}" = "null" ]; then
echo "No matching open milestone found for parsed version '${milestone_title}'."
exit 0
fi
milestone="$(gh api "repos/${owner}/${repo}/milestones/${milestone_number}")"
state="$(echo "$milestone" | jq -r '.state')"
open_issues="$(echo "$milestone" | jq -r '.open_issues')"
title="$(echo "$milestone" | jq -r '.title')"
echo "Matched milestone #${milestone_number} '${title}' (state=${state}, open_issues=${open_issues})."
if [ "$state" != "open" ]; then
echo "Milestone is already closed. Nothing to do."
exit 0
fi
if [ "$open_issues" -ne 0 ]; then
echo "Milestone has open items. Skipping close."
exit 0
fi
gh api -X PATCH "repos/${owner}/${repo}/milestones/${milestone_number}" -f state="closed" >/dev/null
echo "Milestone #${milestone_number} closed."