Repository navigation
209 lines (208 loc) · 8.42 KB
/
Copy pathcentralized-release.yml
File metadata and controls
209 lines (208 loc) · 8.42 KB
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
# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
name: centralized-release
on:
push:
branches:
- main
jobs:
setup_release:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.next_version.outputs.version }}
tag_exists: ${{ steps.next_version.outputs.tag_exists }}
latest_commit: ${{ steps.git_remote.outputs.latest_commit }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Git Identity
run: |-
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
- name: Fetch current NPM package versions
id: npm_versions
run: |-
get_version() { npm view "$1" version 2>/dev/null || echo "0.0.0"; }
PACKAGES="@aws/app-framework-for-github-apps-on-aws-ops-tools @aws/app-framework-for-github-apps-on-aws-client @aws/app-framework-for-github-apps-on-aws-ssdk @aws/app-framework-for-github-apps-on-aws"
VERSIONS=()
echo "Found NPM versions:"
for pkg in $PACKAGES; do
version=$(get_version "$pkg")
echo "$pkg: $version"
VERSIONS+=("$version")
done
LATEST_NPM=$(printf "%s\n" "${VERSIONS[@]}" | sort -V | tail -n1)
echo "Latest NPM version: $LATEST_NPM"
echo "latest_npm=$LATEST_NPM" >> $GITHUB_OUTPUT
- name: Find Next Available Version
id: next_version
run: |-
LATEST_NPM="${{ steps.npm_versions.outputs.latest_npm }}"
IFS="." read -r major minor patch <<< "$LATEST_NPM"
CANDIDATE_VERSION="$major.$minor.$((patch + 1))"
echo "Starting with candidate version: $CANDIDATE_VERSION"
while git ls-remote --tags origin "refs/tags/v$CANDIDATE_VERSION" | grep -q "v$CANDIDATE_VERSION"; do
echo "Tag v$CANDIDATE_VERSION already exists, trying next version"
patch=$((patch + 1))
CANDIDATE_VERSION="$major.$minor.$patch"
done
echo "Next available version: $CANDIDATE_VERSION"
echo "version=$CANDIDATE_VERSION" >> $GITHUB_OUTPUT
echo "tag_exists=false" >> $GITHUB_OUTPUT
- name: Check for new commits
id: git_remote
run: echo "latest_commit=$(git ls-remote origin -h ${{ github.ref }} | cut -f1)" >> $GITHUB_OUTPUT
app_framework_for_github_apps_on_aws_ops_tools:
needs: setup_release
if: needs.setup_release.outputs.tag_exists != 'true' && needs.setup_release.outputs.latest_commit == github.sha
permissions:
contents: read
id-token: write
uses: ./.github/workflows/build-package-artifact.yml
with:
version: ${{ needs.setup_release.outputs.version }}
package_name: app-framework-for-github-apps-on-aws-ops-tools
package_path: src/packages/app-framework-ops-tools
secrets: inherit
app_framework_for_github_apps_on_aws_client:
needs: setup_release
if: needs.setup_release.outputs.tag_exists != 'true' && needs.setup_release.outputs.latest_commit == github.sha
permissions:
contents: read
id-token: write
uses: ./.github/workflows/build-package-artifact.yml
with:
version: ${{ needs.setup_release.outputs.version }}
package_name: app-framework-for-github-apps-on-aws-client
package_path: src/packages/smithy/build/smithy/source/typescript-client-codegen
secrets: inherit
app_framework_for_github_apps_on_aws_ssdk:
needs: setup_release
if: needs.setup_release.outputs.tag_exists != 'true' && needs.setup_release.outputs.latest_commit == github.sha
permissions:
contents: read
id-token: write
uses: ./.github/workflows/build-package-artifact.yml
with:
version: ${{ needs.setup_release.outputs.version }}
package_name: app-framework-for-github-apps-on-aws-ssdk
package_path: src/packages/smithy/build/smithy/source/typescript-ssdk-codegen
secrets: inherit
app_framework_for_github_apps_on_aws:
needs: setup_release
if: needs.setup_release.outputs.tag_exists != 'true' && needs.setup_release.outputs.latest_commit == github.sha
permissions:
contents: read
id-token: write
uses: ./.github/workflows/build-package-artifact.yml
with:
version: ${{ needs.setup_release.outputs.version }}
package_name: app-framework-for-github-apps-on-aws
package_path: src/packages/app-framework
secrets: inherit
npm_publish:
needs:
- setup_release
- app_framework_for_github_apps_on_aws_ops_tools
- app_framework_for_github_apps_on_aws_client
- app_framework_for_github_apps_on_aws_ssdk
- app_framework_for_github_apps_on_aws
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
env:
CI: "true"
if: needs.setup_release.outputs.tag_exists != 'true' && needs.setup_release.outputs.latest_commit == github.sha
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Git Identity
run: |-
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
- name: Set package list
run: echo "PACKAGES=@aws/app-framework-for-github-apps-on-aws-ops-tools @aws/app-framework-for-github-apps-on-aws-client @aws/app-framework-for-github-apps-on-aws-ssdk @aws/app-framework-for-github-apps-on-aws" >> $GITHUB_ENV
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: https://registry.npmjs.org
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Extract package artifacts for publishing
run: |-
for pkg in $PACKAGES; do
echo "Extracting $pkg..."
# Extract just the package name (remove scope)
dir_name=$(echo "$pkg" | sed "s|.*/||")
# Use the same package name that was passed to build workflow
safe_name="$dir_name"
mkdir -p "$dir_name"
tar -xzf "${safe_name}.tgz" -C "$dir_name" --strip-components=1
done
- name: Patch version and Remove prepack in each package
run: |-
version="${{ needs.setup_release.outputs.version }}"
for pkg in $PACKAGES; do
dir_name=$(echo "$pkg" | sed "s|.*/||")
echo "Patching version in $dir_name/package.json"
cd "$dir_name"
jq --arg ver "$version" '.version = $ver' package.json > tmp.json && mv tmp.json package.json
jq 'del(.scripts.prepack)' package.json > tmp.json && mv tmp.json package.json
cd ..
done
- name: Publish all packages to NPM registry
id: publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |-
version='${{ needs.setup_release.outputs.version }}'
for pkg in $PACKAGES; do
dir_name=$(echo "$pkg" | sed "s|.*/||")
echo "Publishing $pkg@$version"
cd "$dir_name"
npm publish --access public
echo "Successfully published $pkg@$version"
cd ..
done
echo "All packages published successfully"
echo "publishing_failed=false" >> $GITHUB_OUTPUT
- name: Create Git Tag
run: |-
TAG="v${{ needs.setup_release.outputs.version }}"
git tag "$TAG"
git push origin "$TAG"
echo "Created and pushed tag: $TAG"
working-directory: ${{ github.workspace }}
github_release:
needs:
- npm_publish
- setup_release
runs-on: ubuntu-latest
permissions:
contents: write
env:
CI: "true"
if: needs.setup_release.outputs.tag_exists != 'true' && needs.setup_release.outputs.latest_commit == github.sha
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create "v${{ needs.setup_release.outputs.version }}" --title "v${{ needs.setup_release.outputs.version }}" --notes "Automated release for all packages" --target $(git rev-parse HEAD) *.tgz
concurrency:
group: release
cancel-in-progress: false