-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
216 lines (213 loc) · 7.98 KB
/
action.yml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: "P6 GHA: Releases and Publishes a CDK Construct to NPMJS, PYPI, Nuget, GoLang, Maven"
description: "P6 GHA: Releases and Publishes a CDK Construct to NPMJS, PYPI, Nuget, GoLang, Maven"
author: "Philip M. Gollucci"
inputs:
aws_region:
description: "AWS region for deployment"
required: false
default: "us-east-1"
aws_role:
description: "AWS role to assume"
required: true
aws_session_name:
description: "Session name for the AWS role"
required: true
cdk_deploy_account:
description: "AWS CDK deploy account"
required: true
cdk_deploy_region:
description: "AWS CDK deploy region"
required: true
npm_token:
description: "NPM token"
required: true
twine_username:
description: "Twine username"
required: true
twine_password:
description: "Twine password"
required: true
nuget_api_key:
description: "Nugget API key"
required: true
go_github_token:
description: "Go Github token"
required: true
p6_a_gh_token:
description: "GitHub token"
required: true
runs:
using: "composite"
steps:
- name: Checkout code
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5.3.0
with:
python-version: "3.x"
- name: Install Node.js
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
run: |
curl -fsSL https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-x64.tar.xz -o node-v22.11.0-linux-x64.tar.xz
sudo tar -xJf node-v22.11.0-linux-x64.tar.xz -C /usr/local
echo "/usr/local/node-v22.11.0-linux-x64/bin" >> $GITHUB_PATH
- name: Restore NPM node_modules cache
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
uses: actions/cache/restore@v4.1.2
with:
path: node_modules
key: ${{ runner.os }}-yarn-node_modules-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-node_modules-
- name: Corepack
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
run: |
set +e
sudo corepack enable
sudo corepack prepare yarn@latest --activate
- name: Check Node
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
run: |
set +e
ls -alFh /usr/local/node-v22.11.0-linux-x64/bin
which node
which npm
which yarn
which corepack
node -v
npm -v
yarn --version
corepack --version
echo $PATH
- name: Install node_modules
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
run: |
yarn install
yarn explain peer-requirements
- name: Cache NPM dependencies
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
uses: actions/cache@v4.1.2
with:
path: node_modules
key: ${{ runner.os }}-yarn-node_modules-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-node_modules-
- name: Bump Version
id: bump
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
run: |
set -x
latest_tag=$(git tag --list "v*" --sort=-v:refname | head -1)
log_lines=$(git log $latest_tag..HEAD --pretty="format:- %s")
major=$(echo $latest_tag | cut -d. -f1 | sed -e 's,^v,,')
minor=$(echo $latest_tag | cut -d. -f2)
patch=$(echo $latest_tag | cut -d. -f3)
if echo "$log_lines" | grep -q "BREAKING CHANGE"; then
major=$((major + 1))
minor=0
patch=0
elif echo "$log_lines" | grep -q "major"; then
major=$((major + 1))
minor=0
patch=0
elif echo "$log_lines" | grep -q "feat"; then
minor=$((minor + 1))
patch=0
elif echo "$log_lines" | grep -q "fix"; then
patch=$((patch + 1))
elif echo "$log_lines" | grep -v "chore(release):" | grep -q "chore"; then
patch=$((patch + 1))
else
true
fi
new_tag="v$major.$minor.$patch"
npm version $new_tag --no-git-tag-version
mkdir -p dist/
echo $new_tag >dist/releasetag.txt
echo "$log_lines" | grep -v "chore(release):" >dist/changelog.md
echo "Semantic version tag: $latest_tag -> $new_tag"
echo "ChangeLog:"
cat dist/changelog.md
if grep -E "^- (chore|fix|feat|major)\!*" dist/changelog.md; then
echo "bump=true" >> $GITHUB_OUTPUT
else
echo "bump=false" >> $GITHUB_OUTPUT
fi
set +x
- name: Github Release
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.p6_a_gh_token }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
run: |
set -x
tag_name=$(cat dist/releasetag.txt)
if gh release view "$tag_name" -R "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
echo "Release with tag $tag_name already exists. Skipping release creation."
else
gh release create "$tag_name" -R "$GITHUB_REPOSITORY" -F dist/changelog.md -t "$tag_name" --target "$GITHUB_REF"
echo "Release with tag $tag_name created successfully."
fi
- name: Assume role using OIDC
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-region: ${{ inputs.aws_region }}
role-to-assume: ${{ inputs.aws_role }}
role-session-name: ${{ inputs.aws_session_name }}
- name: Run build
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
env:
CDK_DEPLOY_ACCOUNT: ${{ inputs.cdk_deploy_account }}
CDK_DEPLOY_REGION: ${{ inputs.cdk_deploy_region }}
CDK_DEFAULT_ACCOUNT: ${{ inputs.cdk_deploy_account }}
CDK_DEFAULT_REGION: ${{ inputs.cdk_deploy_region }}
AWS_REGION: ${{ inputs.aws_region }}
run: yarn run ci:gha
- name: Run Package
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
run: yarn run jsii:pacmak:parallel
- name: Publish to NPM
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
env:
NPM_TOKEN: ${{ inputs.npm_token }}
run: yarn run publish:npm
- name: Publish to PYPI
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
env:
TWINE_USERNAME: ${{ inputs.twine_username }}
TWINE_PASSWORD: ${{ inputs.twine_password }}
shell: bash
run: yarn run publish:pypi
- name: Publish to Nuget
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
env:
NUGET_API_KEY: ${{ inputs.nuget_api_key }}
shell: bash
run: yarn run publish:nuget
- name: Publish to GoLang
if: ${{ steps.bump.outputs.bump == 'true' && !contains(github.event.head_commit.message, 'chore(release):') }}
shell: bash
env:
GIT_USER_NAME: ${{ github.actor }}
GIT_USER_EMAIL: ${{ github.actor }}@users.noreply.github.com
GH_TOKEN: ${{ inputs.go_github_token }}
GITHUB_TOKEN: ${{ inputs.go_github_token }}
run: |
git config --global user.name "$GIT_USER_NAME"
git config --global user.email "$GIT_USER_EMAIL"
git remote set-url origin "https://$GH_TOKEN@github.com/$GITHUB_REPOSITORY.git"
yarn run publish:golang