forked from amplication/amplication
-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (166 loc) · 7.07 KB
/
release.blueprint-dsg.production.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
name: Release blueprints dsg to production
run-name: Release Blueprints DSG Version ${{ github.event.inputs.version }}
on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: Version used create a new release. i.e. v1.0.0, v1.1.2, v2.0.1
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
ECHO_RED: '\033[0;31m'
ECHO_YELLOW: '\033[0;33m'
ECHO_GREEN: '\033[0;32m'
DSG_PACKAGE_JSON: packages/generator-blueprints/package.json
jobs:
check-version:
name: Check version syntax
runs-on: ubuntu-latest
steps:
- name: Check version is SemVer
run: |
if ! [[ "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version '${{ inputs.version }}'."
echo "Version must be a valid semver version. i.e. v1.0.0, v1.1.2, v2.0.1"
echo "See https://semver.org/ for more details."
exit 1
fi
shell: bash
release-dsg:
name: Create a release for generator-blueprints
runs-on: ubuntu-latest
needs: check-version
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_PRODUCTION_PAT }}
- name: Determine if it's a new generator-blueprints version, and its previous tag
id: check-tag
run: |
DSG_VERSION=v$(cat $DSG_PACKAGE_JSON | jq -r '.version')
NEW_TAG=bpg/${{ inputs.version }}
echo "🏷️ NEW_TAG=$NEW_TAG (based on $DSG_PACKAGE_JSON DSG_VERSION=$DSG_VERSION)"
if [[ "${{ inputs.version }}" == "$DSG_VERSION" ]]; then
echo -e "$ECHO_RED 🚨 The chosen version '${{ inputs.version }}' already defined in generator-blueprints package.json. 🚨"
exit 1
fi
# If the tag already exists, it means that was already released. So we skip it.
if git tag --list | grep -q "^$NEW_TAG"; then
echo -e "$ECHO_RED 🚨 generator-blueprints version '$NEW_TAG' already exists (so it was already released). 🚨"
echo -e "$ECHO_YELLOW If there are no generator-blueprints container images tagged with ${{ inputs.version }}, delete the git tag ${NEW_TAG} and retry."
exit 1
else
# create temporary tag to get the previous tag
git tag $NEW_TAG
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -A 1 ^$NEW_TAG | tail -n 1)
echo "previous-tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "new-tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "new-dsg-version=$DSG_VERSION" >> $GITHUB_OUTPUT
echo "🚀 New version detected"
echo " 🏷️ generator-blueprints version: $DSG_VERSION"
echo " 🏷️ NEW_TAG: $NEW_TAG"
echo " 🏷️ PREVIOUS_TAG: $PREVIOUS_TAG "
fi
- name: Update generator-blueprints package.json
id: update-package-json
run: |
VERSION="${{ inputs.version }}"
APP_VERSION=${VERSION:1}
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "jq is not installed. Please install jq to use this script."
exit 1
fi
# Update the version in package.json
jq ".version = \"$APP_VERSION\"" $DSG_PACKAGE_JSON > temp-package.json && mv temp-package.json $DSG_PACKAGE_JSON
echo "Version in package.json updated to $APP_VERSION"
cat $DSG_PACKAGE_JSON
- name: Commit changes
id: commit-changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(dsg): bump version to ${{ inputs.version }}"
commit_user_name: amplication-engineering
commit_user_email: [email protected]
commit_author: amplication-engineering <[email protected]> # defaults to author of the commit that triggered the run
- name: Build generator-blueprints Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v4
with:
fromTag: "${{ steps.check-tag.outputs.previous-tag }}"
toTag: "${{ steps.commit-changes.outputs.commit_hash }}"
configurationJson: |
{
"ignore_labels": [
"ignore-from-release-notes"
],
"template": "#{{CHANGELOG}}\n\n**Full Changelog**: [#{{FROM_TAG}}...${{ steps.check-tag.outputs.new-tag }}](https://github.com/amplication/amplication/compare/#{{FROM_TAG}}...${{ steps.check-tag.outputs.new-tag }})",
"pr_template": "- #{{TITLE}} by @#{{AUTHOR}} in [##{{NUMBER}}](#{{URL}})",
"categories": [
{
"title": "## What's Changed? 🛠",
"exhaustive_rules": "true",
"rules": [
{
"pattern": "app:generator-blueprints",
"on_property": "labels",
"flags": "gu"
}
]
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version-file: "package.json"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Cache global node modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: npm ci
- name: Configure AWS Credentials (operations account)
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR (operations account)
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: "true"
registries: "439403303254"
- name: Dockerize
run: npx nx package:container generator-blueprints --prod
env:
INPUT_PUSH: true
# env variables substituted in the project.json docker target build-args
GIT_REF_NAME: ${{ inputs.version }}
GIT_SHA: ${{ steps.commit-changes.outputs.commit_hash }}
PRODUCTION_TAGS: true
- name: Create generator-blueprints git tag
run: |
NEW_TAG="${{ steps.check-tag.outputs.new-tag }}"
git push origin $NEW_TAG
- name: Generate release notes artifact
run: |
echo "${{ steps.changelog.outputs.changelog }}" >> release-notes.md
cat release-notes.md
- name: Upload release notes artifact
uses: actions/upload-artifact@v3
with:
name: generator-blueprints release notes
path: release-notes.md