Skip to content

Commit 25032c6

Browse files
authored
Merge pull request #8 from github/devm33/add-publish-workflow
Add npm publish workflow with OIDC trusted publishing
2 parents d069621 + b22e5fb commit 25032c6

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
concurrency:
25+
group: publish-npm
26+
cancel-in-progress: false
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Setup Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 22
37+
registry-url: "https://registry.npmjs.org"
38+
cache: npm
39+
40+
- name: Get current npm version
41+
id: current_version
42+
run: |
43+
CURRENT_VERSION=$(npm view @github/copilot-engine-sdk version 2>/dev/null || echo "0.0.0")
44+
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
45+
echo "Current published version: $CURRENT_VERSION"
46+
echo "- Current published version: \`$CURRENT_VERSION\`" >> "$GITHUB_STEP_SUMMARY"
47+
48+
- name: Calculate next version
49+
id: next_version
50+
run: |
51+
CURRENT="${{ steps.current_version.outputs.version }}"
52+
NEXT_VERSION=$(npx --yes semver "$CURRENT" -i "$VERSION_TYPE")
53+
if [ -z "$NEXT_VERSION" ]; then
54+
echo "Failed to calculate next version from $CURRENT using increment $VERSION_TYPE" >&2
55+
exit 1
56+
fi
57+
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
58+
echo "Next version: $NEXT_VERSION (incremented $VERSION_TYPE from $CURRENT)"
59+
echo "- Next version: \`$NEXT_VERSION\` (incremented $VERSION_TYPE from \`$CURRENT\`)" >> "$GITHUB_STEP_SUMMARY"
60+
env:
61+
VERSION_TYPE: ${{ inputs.version_type }}
62+
63+
- name: Set package version
64+
env:
65+
VERSION: ${{ steps.next_version.outputs.version }}
66+
run: npm version "$VERSION" --no-git-tag-version
67+
68+
- name: Install dependencies
69+
run: npm ci
70+
71+
- name: Build
72+
run: npm run build
73+
74+
- name: Create npm tarball
75+
run: npm pack
76+
77+
- name: Publish to npm
78+
run: npm publish --access public 2>&1 | tee -a "$GITHUB_STEP_SUMMARY"
79+
80+
- name: Determine previous release tag
81+
id: previous_tag
82+
run: |
83+
PREVIOUS_TAG=$(gh release list --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName // empty' 2>/dev/null || echo "")
84+
echo "tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT"
85+
if [ -n "$PREVIOUS_TAG" ]; then
86+
echo "Previous release tag: $PREVIOUS_TAG"
87+
echo "- Previous release tag: \`$PREVIOUS_TAG\`" >> "$GITHUB_STEP_SUMMARY"
88+
else
89+
echo "No previous release found"
90+
echo "- No previous release found" >> "$GITHUB_STEP_SUMMARY"
91+
fi
92+
env:
93+
GH_TOKEN: ${{ github.token }}
94+
95+
- name: Create GitHub release
96+
env:
97+
VERSION: ${{ steps.next_version.outputs.version }}
98+
PREVIOUS_TAG: ${{ steps.previous_tag.outputs.tag }}
99+
GH_TOKEN: ${{ github.token }}
100+
run: |
101+
TAG="v${VERSION}"
102+
103+
RELEASE_ARGS=(
104+
"$TAG"
105+
--title "$TAG"
106+
--generate-notes
107+
./*.tgz
108+
)
109+
110+
if [ -n "$PREVIOUS_TAG" ]; then
111+
RELEASE_ARGS+=(--notes-start-tag "$PREVIOUS_TAG")
112+
fi
113+
114+
gh release create "${RELEASE_ARGS[@]}" 2>&1 | tee -a "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)