Skip to content

Commit e9b806c

Browse files
authored
Add GitHub Actions workflows for hybrid npm/Maven/NuGet publishing (#1099)
## Problem Relied on Github Actions to do the version increment, but actually any commits going into main but be done via PR, or have the appropriate permissions ``` remote: error: GH013: Repository rule violations found for refs/heads/main. remote: Review all repository rules at https://github.com/aws/aws-toolkit-common/rules?ref=refs%2Fheads%2Fmain remote: remote: - Changes must be made through a pull request. remote: remote: - 4 of 4 required status checks are expected. remote: To https://github.com/aws/aws-toolkit-common ! [remote rejected] main -> main (push declined due to repository rule violations) error: failed to push some refs to 'https://github.com/aws/aws-toolkit-common' Error: Process completed with exit code 1. ``` ## Solution Codepipelines has permission as it authenticates as `aws-toolkit-automation` user with write permissions to be able to push commits directly into `main` ### New Flow 1. When user merges PR to main, triggers Github Actions workflow which immediately triggers the CodePipeline 2. CodePipeline goes through stages 1. clone repo 2. aws-toolkit-automation commits version increment to main 3. build maven/nuget 4. publish maven/nuget 3. When aws-toolkit-automation commits version increment to main, Github Actions workflow will publish npm <!--- 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 c91929c commit e9b806c

File tree

2 files changed

+32
-67
lines changed

2 files changed

+32
-67
lines changed

.github/workflows/publish.yml

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
name: Publish packages
1+
name: Publish npm package
22

33
on:
4-
workflow_dispatch:
54
push:
65
branches: [main]
76

87
permissions:
98
id-token: write # Required for OIDC authentication with npm
10-
contents: write # Required to push version commits
119

1210
jobs:
13-
publish:
11+
publish-npm:
12+
# Only run if the commit is from aws-toolkit-automation (version increment)
13+
if: github.event.head_commit.author.name == 'aws-toolkit-automation'
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v4
17-
with:
18-
token: ${{ secrets.GITHUB_TOKEN }}
1917

2018
- name: Setup Node.js
2119
uses: actions/setup-node@v4
@@ -24,71 +22,12 @@ jobs:
2422
registry-url: 'https://registry.npmjs.org'
2523
scope: '@aws-toolkits'
2624

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
25+
- name: Build and publish npm package
7326
run: |
7427
VERSION=$(cat version)
28+
echo "Publishing npm package version: $VERSION"
7529
cd telemetry/vscode
7630
npm ci
7731
npm version "$VERSION"
7832
npm pack
79-
80-
- name: Publish to npm
81-
run: |
82-
cd telemetry/vscode
8333
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
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Trigger CodePipeline for Maven/NuGet
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
id-token: write # Required for OIDC authentication with AWS
9+
10+
jobs:
11+
trigger-pipeline:
12+
# Only run if NOT from aws-toolkit-automation (avoid triggering on version commits)
13+
if: github.event.head_commit.author.name != 'aws-toolkit-automation'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Configure AWS credentials
17+
uses: aws-actions/configure-aws-credentials@v4
18+
with:
19+
role-to-assume: arn:aws:iam::305657142372:role/GitHubActionsCodePipelineRole
20+
role-session-name: github-actions-codepipeline
21+
aws-region: us-west-2
22+
23+
- name: Trigger CodePipeline for Maven/NuGet
24+
run: |
25+
echo "Triggering CodePipeline for user commit by ${{ github.event.head_commit.author.name }}"
26+
aws codepipeline start-pipeline-execution --name PackagePipeline

0 commit comments

Comments
 (0)