Skip to content

Commit c91929c

Browse files
authored
github actions workflow to publish to npm and then trigger codepipeline to publish to maven/nuget (#1098)
## Problem The current publishing process runs everything through CodePipeline with hourly triggers, using classic npm tokens and mixed authentication patterns. Context: npm has changed granular tokens from unlimited expiration to 90-day max limit: https://github.blog/changelog/2025-09-29-strengthening-npm-security-important-changes-to-authentication-and-token-management/#granular-npm-access-token-lifetime-limits ## Solution ### Implement a hybrid approach GitHub Actions handles npm publishing: - Uses OIDC authentication, eliminating token expiration issues - Triggered only when commits are merged to main, removing the need for hourly triggers - Centralizes version management and git operations CodePipeline continues to handle Maven and NuGet publishing: - Triggered on-demand by GitHub Actions after npm publishing - Maintains existing authentication patterns for these package types - Ensures version consistency across all packages ### Benefits: - Eliminates npm token rotation burden with OIDC authentication - Reduces resource waste with on-demand execution instead of hourly runs - Improves security with modern authentication patterns - Synchronizes versions across all package managers ## Note verison is bumped from `1.0.331` --> `1.0.335` as used a few versions for testing <!--- REMINDER: - Read CONTRIBUTING.md first. - Add test coverage for your changes. - Link to related issues/commits. - Testing: how did you test your changes? - Screenshots if applicable --> ## License By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent c79467c commit c91929c

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

.github/workflows/publish.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Publish packages
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
8+
permissions:
9+
id-token: write # Required for OIDC authentication with npm
10+
contents: write # Required to push version commits
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '24.x'
24+
registry-url: 'https://registry.npmjs.org'
25+
scope: '@aws-toolkits'
26+
27+
- name: Validate release commits
28+
run: |
29+
VERSION=$(cat version)
30+
echo "validating for package version: $VERSION"
31+
32+
# Now we check if there are any "interesting" commits to create a release version. These are any
33+
# commits that are neither 1. from dependabot or 2. a release commit.
34+
AUTHOR_DEPENDABOT="dependabot[bot]"
35+
AUTHOR_AUTOMATION="aws-toolkit-automation"
36+
37+
SHOULD_RELEASE=false
38+
for author in $(git log --pretty=%an)
39+
do
40+
if [ "$author" = $AUTHOR_DEPENDABOT ]; then
41+
# Ignore dependabot commits, keep searching.
42+
continue
43+
elif [ "$author" != $AUTHOR_AUTOMATION ]; then
44+
# Found a commit to release since last release.
45+
SHOULD_RELEASE=true
46+
echo "found at least one commit to release, author: $author"
47+
fi
48+
49+
# If the commit wasn't from dependabot, then we have enough information.
50+
break
51+
done
52+
53+
if [ $SHOULD_RELEASE != true ]; then
54+
echo "no commits detected that are not from '$AUTHOR_DEPENDABOT' or '$AUTHOR_AUTOMATION'. skipping release."
55+
exit 1
56+
fi
57+
58+
- name: Increment version and commit
59+
run: |
60+
git config --global user.name "aws-toolkit-automation"
61+
git config --global user.email "<>"
62+
63+
# increase the version
64+
cat version | (IFS="." ; read a b c && echo $a.$b.$((c + 1)) > version)
65+
VERSION=$(cat version)
66+
echo "version is now: $VERSION"
67+
68+
git add version
69+
git commit -m "Release version $VERSION"
70+
git push origin main
71+
72+
- name: Build npm package
73+
run: |
74+
VERSION=$(cat version)
75+
cd telemetry/vscode
76+
npm ci
77+
npm version "$VERSION"
78+
npm pack
79+
80+
- name: Publish to npm
81+
run: |
82+
cd telemetry/vscode
83+
npm publish $(ls -1 *.tgz) --access public
84+
85+
- name: Configure AWS credentials
86+
uses: aws-actions/configure-aws-credentials@v4
87+
with:
88+
role-to-assume: arn:aws:iam::305657142372:role/GitHubActionsCodePipelineRole
89+
role-session-name: github-actions-codepipeline
90+
aws-region: us-west-2
91+
92+
- name: Trigger CodePipeline for Maven/NuGet
93+
run: |
94+
aws codepipeline start-pipeline-execution --name PackagePipeline

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.331
1+
1.0.335

0 commit comments

Comments
 (0)