-
Notifications
You must be signed in to change notification settings - Fork 3
219 lines (184 loc) Β· 7.17 KB
/
checks.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
217
218
219
name: Pipeline
on:
pull_request:
paths-ignore:
- "**.md"
- "!.changeset/**"
push:
branches:
# latest release
- main
# maintenance releases
- v[0-9]+.x.x
- v[0-9]+.[0-9]+.x
env:
CI: true
HELM_CHART_BRANCH: gh-pages
jobs:
checks:
name: Checks
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Check for Uncommitted Changes
run: |
git diff --name-only --exit-code --relative || (echo "\nUncommitted changes found π" && exit 1)
- name: Read Changeset Status
id: changeset-status
if: github.event_name == 'pull_request'
uses: ./.github/actions/changeset-status
with:
args: --since origin/${{ github.base_ref }}
- name: Check Version Changes
if: steps.changeset-status.outputs != ''
run: |
# TODO delete
${{ toJson(steps.changeset-status.outputs) }}
BASE_BRANCH=$(jq -r '.baseBranch' .changeset/config.json)
VERSION_TYPE="${{ steps.changeset-status.outputs.type }}"
# Check for invalid version bumps based on the branch type
if [[ "$BASE_BRANCH" =~ ^v[0-9]+\.[0-9]+\.x$ && "$VERSION_TYPE" != "patch" ]]; then
echo "π¨ Detected '$VERSION_TYPE' bump."
echo "π¨ Only 'patch' versions are allowed for the maintenance branch $BASE_BRANCH."
exit 1
fi
if [[ "$BASE_BRANCH" =~ ^v[0-9]+\.x\.x$ && "$VERSION_TYPE" == "major" ]]; then
echo "π¨ Detected '$VERSION_TYPE' bump."
echo "π¨ Only 'patch' or 'minor' versions are allowed for the maintenance branch $BASE_BRANCH."
exit 1
fi
echo "β
Detected '$VERSION_TYPE' bump."
- name: Detect File Changes
id: changed-files
uses: tj-actions/changed-files@v41
with:
files_yaml: |
eslint_config:
- .eslintrc.js
- .eslintignore
- yarn.lock
eslint_target:
- '**/*.{ts,js,vue}'
- name: Lint all files
if: ${{ github.event_name == 'push' || steps.changed-files.outputs.eslint_config_any_changed == 'true' }}
run: yarn lint .
- name: Lint changed files
if: ${{ steps.lint-all.outcome == 'skipped' && steps.changed-files.outputs.eslint_target_any_changed == 'true' }}
run: yarn lint ${{ steps.changed-files.outputs.eslint_target_all_changed_files }} --no-error-on-unmatched-pattern
- name: Build Observability Package
run: yarn build-pkg observability
build:
name: Build and Version
runs-on: ubuntu-latest
# runs only on pushes so it does not run on PRs
if: github.event_name == 'push'
outputs:
tagged_release: ${{ steps.changesets-output.outputs.tagged_release }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Read Changesets Config
id: changeset-config
run: |
BASE_BRANCH=$(jq -r '.baseBranch' .changeset/config.json)
echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
- name: Determine Release Details
id: release-details
# runs only when the .changeset.baseBranch is the target branch
if: steps.changeset-config.outputs.base_branch == '${{ github.ref_name }}'
run: |
OUTPUT=$(mktemp ${{runner.temp}}/changeset-output.XXXXXX.json)
if [ ! -f "$OUTPUT" ]; then
echo "Failed to create temp file at: $OUTPUT"
exit 1
fi
echo "Temporary file created at: $OUTPUT"
# the `changeset status` command uses path.join so the path should be relative
yarn changeset status --output $(realpath --relative-to . $OUTPUT)
if [ ! -s "$OUTPUT" ]; then
echo "Error: Temporary file is empty after running 'yarn changeset status'"
exit 1
fi
MESSAGE=$(jq -r 'if .releases | length > 0 then .releases[0] | "π Release `\(.name)@\(.oldVersion) β \(.newVersion)`" else "Publishing release..." end' "$OUTPUT")
echo "message=$MESSAGE" >> $GITHUB_OUTPUT
# creates a PR if there are changesets or assign the new tag if the PR is merged
- name: Create Release Pull Request or Publish
id: changesets
if: steps.release-details.outputs.message
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: changesets/action@v1
with:
title: ${{ steps.release-details.outputs.message }}
commit: ${{ steps.release-details.outputs.message }}
# define the publish command, so changeset creates a release in GitHub
publish: yarn release-tag
- name: Extract Published Version
id: changesets-output
if: steps.changesets.outputs.published == 'true'
# extract the first package name and version and format as `name-version`
# the publish-pkgs script expects `name-version` but not `name@version`
# so `release-tag` creates both but outputs only the default changeset format
run: |
TAGGED_RELEASE=$(echo '${{ steps.changesets.outputs.publishedPackages }}' | jq -r '.[0] | "\(.name)-\(.version)"')
echo "tagged_release=$TAGGED_RELEASE" >> $GITHUB_OUTPUT
- name: Preare Build Artifact
id: prepare-artifact
if: steps.changesets-output.outputs.tagged_release
run: |
yarn publish-pkgs \
-s "${{ github.repository }}" \
-b "${{ env.HELM_CHART_BRANCH }}" \
-t "${{ steps.changesets-output.outputs.tagged_release }}"
- name: Upload Charts Artifact
if: steps.prepare-artifact.conclusion == 'success'
uses: actions/upload-artifact@v3
with:
name: charts
path: tmp
if-no-files-found: error
release:
name: Helm Release
needs:
- build
- checks
if: needs.build.outputs.tagged_release
runs-on: ubuntu-latest
steps:
- name: Checkout Target Branch
uses: actions/checkout@v4
with:
ref: "${{ env.HELM_CHART_BRANCH }}"
- name: Configure Git User
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Set Up Helm CLI
uses: azure/setup-helm@v3
with:
version: v3.8.0
- name: Download Build Artifact
uses: actions/download-artifact@v3
with:
name: charts
- name: Commit and Push Changes
run: |
git add ./{assets,charts,extensions,index.yaml}
git commit -m "CI: Publish Helm charts for ${{ needs.build.outputs.tagged_release }}"
git push
- name: Run Helm Chart Releaser
uses: helm/chart-releaser-action@v1.4.1
with:
charts_dir: ./charts/*
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_SKIP_EXISTING: true