forked from amplication/amplication
-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (151 loc) · 6.54 KB
/
release.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
name: Release apps to production
run-name: Release Version ${{ github.event.inputs.version }}
on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: Version used to update apps version.ts and create a new release. i.e. v1.0.0, v1.1.2, v2.0.1
draft-release:
type: boolean
description: Create a draft release instead of a published release.
required: false
default: true
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'
jobs:
check-version:
name: Check version syntax
runs-on: ubuntu-latest
steps:
- name: Check version is SemVer
run: |
if ! [[ "${{ github.event.inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version '${{ github.event.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
generate-release:
name: Create a release for amplication platform
runs-on: ubuntu-latest
needs: check-version
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_PRODUCTION_PAT }}
- name: Check version is unique
id: validate-version-unique
run: |
if git tag --list | grep -q "^${{ github.event.inputs.version }}"; then
echo "Version '${{ github.event.inputs.version }}' already exists."
echo "Please use a different version."
exit 1
fi
shell: bash
- name: Create new tag and determine previous tag
run: |
git tag ${{ github.event.inputs.version }}> /dev/null
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -v ^dsg/ | grep -A 1 ^${{ github.event.inputs.version }} | tail -n 1)
echo "🏷️ PREVIOUS_TAG=$PREVIOUS_TAG (used to detect the affected projects)"
echo "previous-tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
git tag -d ${{ github.event.inputs.version }}> /dev/null
id: check-tag
- uses: actions/setup-node@v3
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@v3
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: Check release is needed
run: |
export NX_BASE="${{ steps.check-tag.outputs.previous-tag }}"
AFFECTED_APPS=$(npx nx show projects --affected --json --type=app | jq -c .)
AFFECTED_DEPLOYABLE_CONTAINER_APPS=$(npx nx show projects --affected --json --with-target deploy:container --type=app | jq -c .)
AFFECTED_DEPLOYABLE_STATIC_APPS=$(npx nx show projects --affected --json --with-target deploy:static --type=app | jq -c .)
if [[ $AFFECTED_DEPLOYABLE_CONTAINER_APPS == "[]" ]] && [[ $AFFECTED_DEPLOYABLE_STATIC_APPS == "[]" ]]; then
echo -e "$ECHO_YELLOW affected-apps: $AFFECTED_APPS"
echo -e "$ECHO_YELLOW affected-deploy-container: $AFFECTED_DEPLOYABLE_CONTAINER_APPS"
echo -e "$ECHO_YELLOW affected-deploy-static: $AFFECTED_DEPLOYABLE_STATIC_APPS"
if [[ $AFFECTED_APPS == *"data-service-generator"* ]]; then
echo -e "$ECHO_RED 🚨 Only data-service-generator is affected by this release 🚨"
echo -e "$ECHO_YELLOW Use the \033[1;33mRelease DSG Hotfix workflow${ECHO_YELLOW} instead"
exit 1
fi
echo -e "$ECHO_RED 🚨 No apps affected by this release 🚨"
echo -e "$ECHO_RED Are you sure you want to release?"
exit 1
fi
- name: Update apps version.ts
id: update-version-ts
run: |
VERSION=${{ github.event.inputs.version }}
APP_VERSION=${VERSION:1}
npx nx run-many --target=update-version --args="--version=$APP_VERSION"
# Commit all changed files back to the repository
- name: Commit changes
id: commit-changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore: update apps version.ts"
branch: ${{ github.event.repository.default_branch }}
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 amplication 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: |
{
"template": "#{{CHANGELOG}}\n\n**Full Changelog**: [#{{FROM_TAG}}...${{ github.event.inputs.version }}](https://github.com/amplication/amplication/compare/#{{FROM_TAG}}...${{ github.event.inputs.version }})",
"pr_template": "- #{{TITLE}} by @#{{AUTHOR}} in [##{{NUMBER}}](#{{URL}})",
"empty_template": "",
"ignore_labels": [
"ignore-from-release-notes"
],
"categories": [
{
"title": "## What's Changed?",
"exhaustive_rules": "true",
"rules": [
{
"pattern": "(app|lib):(?!data-service-generator)",
"on_property": "labels",
"flags": "gu"
}
]
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release amplication
id: release
if: ${{ steps.changelog.outputs.changelog != '' }}
uses: softprops/action-gh-release@v1
with:
name: ${{ github.event.inputs.version }}
tag_name: ${{ github.event.inputs.version }}
draft: ${{ github.event.inputs.draft-release }}
body: ${{ steps.changelog.outputs.changelog }}