Skip to content

Commit 274890d

Browse files
devm33Copilot
andcommitted
Add npm publish workflow with OIDC trusted publishing
Adds a workflow_dispatch workflow (.github/workflows/publish.yml) that: - Accepts version_type input (major/minor/patch, default patch) - Determines next version from the latest npm-published version - Publishes to npm using OIDC trusted publishing (no tokens needed) - Creates a GitHub release with auto-generated notes and npm tarball - Pipes command output to GITHUB_STEP_SUMMARY for visibility - Hardens against script injection using environment variables Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d069621 commit 274890d

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

.github/workflows/publish.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Publish to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: "Version increment type"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
default: patch
15+
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
jobs:
21+
publish:
22+
runs-on: ubuntu-latest
23+
environment: npm-publish
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Setup Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: 22
34+
registry-url: "https://registry.npmjs.org"
35+
36+
- name: Get current npm version
37+
id: current_version
38+
run: |
39+
CURRENT_VERSION=$(npm view @github/copilot-engine-sdk version 2>/dev/null || echo "0.0.0")
40+
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
41+
echo "Current published version: $CURRENT_VERSION"
42+
echo "- Current published version: \`$CURRENT_VERSION\`" >> "$GITHUB_STEP_SUMMARY"
43+
44+
- name: Calculate next version
45+
id: next_version
46+
env:
47+
CURRENT: ${{ steps.current_version.outputs.version }}
48+
VERSION_TYPE: ${{ inputs.version_type }}
49+
run: |
50+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
51+
52+
case "$VERSION_TYPE" in
53+
major)
54+
MAJOR=$((MAJOR + 1))
55+
MINOR=0
56+
PATCH=0
57+
;;
58+
minor)
59+
MINOR=$((MINOR + 1))
60+
PATCH=0
61+
;;
62+
patch)
63+
PATCH=$((PATCH + 1))
64+
;;
65+
esac
66+
67+
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
68+
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
69+
echo "Next version: $NEXT_VERSION (incremented $VERSION_TYPE from $CURRENT)"
70+
echo "- Next version: \`$NEXT_VERSION\` (incremented $VERSION_TYPE from \`$CURRENT\`)" >> "$GITHUB_STEP_SUMMARY"
71+
72+
- name: Set package version
73+
env:
74+
VERSION: ${{ steps.next_version.outputs.version }}
75+
run: npm version "$VERSION" --no-git-tag-version
76+
77+
- name: Install dependencies
78+
run: npm ci
79+
80+
- name: Build
81+
run: npm run build
82+
83+
- name: Create npm tarball
84+
run: npm pack
85+
86+
- name: Publish to npm
87+
run: npm publish --access public 2>&1 | tee -a "$GITHUB_STEP_SUMMARY"
88+
89+
- name: Determine previous release tag
90+
id: previous_tag
91+
run: |
92+
PREVIOUS_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName // empty' 2>/dev/null || echo "")
93+
echo "tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT"
94+
if [ -n "$PREVIOUS_TAG" ]; then
95+
echo "Previous release tag: $PREVIOUS_TAG"
96+
echo "- Previous release tag: \`$PREVIOUS_TAG\`" >> "$GITHUB_STEP_SUMMARY"
97+
else
98+
echo "No previous release found"
99+
echo "- No previous release found" >> "$GITHUB_STEP_SUMMARY"
100+
fi
101+
env:
102+
GH_TOKEN: ${{ github.token }}
103+
104+
- name: Create GitHub release
105+
env:
106+
VERSION: ${{ steps.next_version.outputs.version }}
107+
PREVIOUS_TAG: ${{ steps.previous_tag.outputs.tag }}
108+
GH_TOKEN: ${{ github.token }}
109+
run: |
110+
TAG="v${VERSION}"
111+
112+
RELEASE_ARGS=(
113+
"$TAG"
114+
--title "$TAG"
115+
--generate-notes
116+
./*.tgz
117+
)
118+
119+
if [ -n "$PREVIOUS_TAG" ]; then
120+
RELEASE_ARGS+=(--notes-start-tag "$PREVIOUS_TAG")
121+
fi
122+
123+
gh release create "${RELEASE_ARGS[@]}" 2>&1 | tee -a "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)