Skip to content

Commit cb3642c

Browse files
authored
Breaking: [AEA-0000] - use common release tagging (#22)
## Summary - Routine Change ### Details - use common release tagging - create pull request workflow - setup sonar scan
1 parent a7ef5c0 commit cb3642c

20 files changed

+498
-6826
lines changed

.devcontainer/Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apt-get update \
99
jq apt-transport-https ca-certificates gnupg-agent \
1010
software-properties-common bash-completion python3-pip make libbz2-dev \
1111
libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev \
12-
xz-utils tk-dev liblzma-dev netcat-traditional libyaml-dev pre-commit
12+
xz-utils tk-dev liblzma-dev netcat-traditional libyaml-dev
1313

1414
USER vscode
1515

@@ -18,15 +18,20 @@ RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3; \
1818
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc; \
1919
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc;
2020

21-
ENV PATH="$PATH:/home/vscode/.asdf/bin/:/workspaces/eps-prescription-tracker-ui/node_modules/.bin"
21+
ENV PATH="$PATH:/home/vscode/.asdf/bin/:/workspaces/eps-prescription-tracker-ui/node_modules/.bin:/workspaces/eps-workflow-quality-checks/.venv/bin"
2222

2323
# Install ASDF plugins#
24-
RUN asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
24+
RUN asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git; \
25+
asdf plugin add actionlint; \
26+
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git; \
27+
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git; \
28+
asdf plugin add python
2529

2630
WORKDIR /workspaces/eps-workflow-quality-checks
2731

2832
ADD .tool-versions /workspaces/eps-workflow-quality-checks/.tool-versions
2933
ADD .tool-versions /home/vscode/.tool-versions
3034

31-
RUN asdf install; \
35+
RUN asdf install python; \
36+
asdf install; \
3237
asdf reshim nodejs;

.gitallowed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
token: ?"?\$\{\{\s*secrets\.GITHUB_TOKEN\s*\}\}"?
2+
.*\.gitallowed.*

.github/config/settings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TAG_FORMAT: "v${version}"

.github/scripts/ignore.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
# dummy file for shellcheck to work

.github/workflows/pull_request.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: pr
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
env:
8+
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
9+
10+
jobs:
11+
pr_title_format_check:
12+
uses: NHSDigital/eps-workflow-semantic-release/.github/workflows/pr_title_check.yml@f80157cecce288dd175e61b477a1d2dbe9c88b99
13+
get_asdf_version:
14+
runs-on: ubuntu-22.04
15+
outputs:
16+
asdf_version: ${{ steps.asdf-version.outputs.version }}
17+
tag_format: ${{ steps.load-config.outputs.TAG_FORMAT }}
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v5
21+
22+
- name: Get asdf version
23+
id: asdf-version
24+
run: echo "version=$(awk '!/^#/ && NF {print $1; exit}' .tool-versions.asdf)" >> "$GITHUB_OUTPUT"
25+
- name: Load config value
26+
id: load-config
27+
run: |
28+
TAG_FORMAT=$(yq '.TAG_FORMAT' .github/config/settings.yml)
29+
echo "TAG_FORMAT=$TAG_FORMAT" >> "$GITHUB_OUTPUT"
30+
quality_checks:
31+
uses: ./.github/workflows/quality-checks.yml
32+
needs: [get_asdf_version]
33+
with:
34+
asdfVersion: ${{ needs.get_asdf_version.outputs.asdf_version }}
35+
secrets:
36+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37+
tag_release:
38+
needs: [quality_checks, get_asdf_version]
39+
uses: NHSDigital/eps-workflow-semantic-release/.github/workflows/tag-release.yml@f80157cecce288dd175e61b477a1d2dbe9c88b99
40+
with:
41+
dry_run: true
42+
asdfVersion: ${{ needs.get_asdf_version.outputs.asdf_version }}
43+
branch_name: ${{ github.event.pull_request.head.ref }}
44+
publish_package: false
45+
tag_format: ${{ needs.get_asdf_version.outputs.tag_format }}
46+
secrets: inherit

.github/workflows/quality-checks.yml

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ on:
1616
description: Toggle to run sonar code analyis on this repository.
1717
default: true
1818
required: false
19+
asdfVersion:
20+
type: string
21+
required: true
1922
reinstall_poetry:
2023
type: boolean
2124
description: Toggle to reinstall poetry on top of python version installed by asdf.
@@ -28,8 +31,8 @@ jobs:
2831
- uses: actions/setup-java@v5
2932
if: ${{ inputs.install_java }}
3033
with:
31-
java-version: '21'
32-
distribution: 'corretto'
34+
java-version: "21"
35+
distribution: "corretto"
3336

3437
- name: Checkout code
3538
uses: actions/checkout@v5
@@ -71,23 +74,23 @@ jobs:
7174
7275
# using git commit sha for version of action to ensure we have stable version
7376
- name: Install asdf
74-
uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
77+
uses: asdf-vm/actions/setup@1902764435ca0dd2f3388eea723a4f92a4eb8302
7578
with:
76-
asdf_branch: v0.14.1
79+
asdf_version: ${{ inputs.asdfVersion }}
7780

7881
- name: Cache asdf
7982
uses: actions/cache@v4
8083
with:
8184
path: |
8285
~/.asdf
83-
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
86+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}-${{ inputs.asdfVersion }}
8487
restore-keys: |
85-
${{ runner.os }}-asdf-
88+
${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}-${{ inputs.asdfVersion }}
8689
8790
- name: Install asdf dependencies in .tool-versions
88-
uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
91+
uses: asdf-vm/actions/install@1902764435ca0dd2f3388eea723a4f92a4eb8302
8992
with:
90-
asdf_branch: v0.14.1
93+
asdf_version: ${{ inputs.asdfVersion }}
9194
env:
9295
PYTHON_CONFIGURE_OPTS: --enable-shared
9396

@@ -96,7 +99,7 @@ jobs:
9699
run: |
97100
poetry_tool_version=$(cat .tool-versions | grep poetry)
98101
poetry_version=${poetry_tool_version//"poetry "}
99-
asdf uninstall poetry $poetry_version
102+
asdf uninstall poetry "$poetry_version"
100103
asdf install poetry
101104
102105
- name: Setting up .npmrc
@@ -113,16 +116,16 @@ jobs:
113116
- name: Check if project uses Poetry
114117
id: check_poetry
115118
run: |
116-
if [ -f pyproject.toml ] && grep -q '\[tool.poetry\]' pyproject.toml; then
119+
if [ -f "pyproject.toml" ] && grep -q '\[tool.poetry\]' "pyproject.toml"; then
117120
echo "****************"
118121
echo "Project uses poetry"
119122
echo "****************"
120-
echo "uses_poetry=true" >> $GITHUB_OUTPUT
123+
echo "uses_poetry=true" >> "$GITHUB_OUTPUT"
121124
else
122125
echo "****************"
123126
echo "Project does not use poetry"
124127
echo "****************"
125-
echo "uses_poetry=false" >> $GITHUB_OUTPUT
128+
echo "uses_poetry=false" >> "$GITHUB_OUTPUT"
126129
fi
127130
128131
- name: Check if project uses Java
@@ -132,27 +135,27 @@ jobs:
132135
echo "****************"
133136
echo "Detected a Java project"
134137
echo "****************"
135-
echo "uses_java=true" >> $GITHUB_OUTPUT
138+
echo "uses_java=true" >> "$GITHUB_OUTPUT"
136139
else
137140
echo "****************"
138141
echo "Project does not use Java"
139142
echo "****************"
140-
echo "uses_java=false" >> $GITHUB_OUTPUT
143+
echo "uses_java=false" >> "$GITHUB_OUTPUT"
141144
fi
142-
145+
143146
- name: Check for SAM templates
144147
id: check_sam_templates
145148
run: |
146149
if [ -d "SAMtemplates" ]; then
147150
echo "****************"
148151
echo "Project has SAM templates"
149152
echo "****************"
150-
echo "sam_exists=true" >> $GITHUB_OUTPUT
153+
echo "sam_exists=true" >> "$GITHUB_OUTPUT"
151154
else
152155
echo "****************"
153156
echo "Project does not have SAM templates"
154157
echo "****************"
155-
echo "sam_exists=false" >> $GITHUB_OUTPUT
158+
echo "sam_exists=false" >> "$GITHUB_OUTPUT"
156159
fi
157160
158161
- name: Check for cloudformation templates
@@ -162,27 +165,27 @@ jobs:
162165
echo "****************"
163166
echo "Project has cloudformation templates"
164167
echo "****************"
165-
echo "cf_exists=true" >> $GITHUB_OUTPUT
168+
echo "cf_exists=true" >> "$GITHUB_OUTPUT"
166169
else
167170
echo "****************"
168171
echo "Project does not have cloudformation templates"
169172
echo "****************"
170-
echo "cf_exists=false" >> $GITHUB_OUTPUT
173+
echo "cf_exists=false" >> "$GITHUB_OUTPUT"
171174
fi
172-
175+
173176
- name: Check for cdk
174177
id: check_cdk
175178
run: |
176179
if [ -d "packages/cdk" ]; then
177180
echo "****************"
178181
echo "Project has cdk"
179182
echo "****************"
180-
echo "cdk_exists=true" >> $GITHUB_OUTPUT
183+
echo "cdk_exists=true" >> "$GITHUB_OUTPUT"
181184
else
182185
echo "****************"
183186
echo "Project does not have cdk"
184187
echo "****************"
185-
echo "cdk_exists=false" >> $GITHUB_OUTPUT
188+
echo "cdk_exists=false" >> "$GITHUB_OUTPUT"
186189
fi
187190
188191
- name: Check licenses (Makefile)
@@ -203,7 +206,7 @@ jobs:
203206
204207
# known packages with dual licensing
205208
IGNORE_PACKAGES="PyGithub chardet text-unidecode"
206-
LICENSES=$(poetry run pip-licenses --ignore-packages ${IGNORE_PACKAGES})
209+
LICENSES=$(poetry run pip-licenses --ignore-packages "${IGNORE_PACKAGES}")
207210
INCOMPATIBLE_LIBS=$(echo "$LICENSES" | grep 'GPL' || true)
208211
209212
if [[ -z $INCOMPATIBLE_LIBS ]]; then
@@ -214,7 +217,7 @@ jobs:
214217
echo "$INCOMPATIBLE_LIBS"
215218
exit 1
216219
fi
217-
220+
218221
- name: Run code lint
219222
run: make lint
220223

@@ -239,12 +242,12 @@ jobs:
239242
240243
- name: Run unit tests
241244
run: make test
242-
245+
243246
- name: Run cdk-synth
244247
if: steps.check_cdk.outputs.cdk_exists == 'true'
245248
run: |
246249
make cdk-synth
247-
250+
248251
- name: Install AWS SAM CLI
249252
if: steps.check_sam_templates.outputs.sam_exists == 'true'
250253
run: |
@@ -339,8 +342,8 @@ jobs:
339342
uses: NHSDigital/eps-action-sbom@main
340343

341344
- name: "check is SONAR_TOKEN exists"
342-
env:
343-
super_secret: ${{ secrets.SONAR_TOKEN }}
345+
env:
346+
super_secret: ${{ secrets.SONAR_TOKEN }}
344347
if: ${{ env.super_secret != '' && inputs.run_sonar == true }}
345348
run: echo "SONAR_TOKEN_EXISTS=true" >> "$GITHUB_ENV"
346349

.github/workflows/release.yml

Lines changed: 28 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,83 +8,37 @@ env:
88
BRANCH_NAME: ${{ github.event.ref.BRANCH_NAME }}
99

1010
jobs:
11-
tag_release:
12-
runs-on: ubuntu-latest
11+
get_asdf_version:
12+
runs-on: ubuntu-22.04
1313
outputs:
14-
version_tag: ${{ steps.output_version_tag.outputs.VERSION_TAG }}
14+
asdf_version: ${{ steps.asdf-version.outputs.version }}
15+
tag_format: ${{ steps.load-config.outputs.TAG_FORMAT }}
1516
steps:
1617
- name: Checkout code
1718
uses: actions/checkout@v5
18-
with:
19-
ref: ${{ env.BRANCH_NAME }}
20-
fetch-depth: 0
21-
22-
# using git commit sha for version of action to ensure we have stable version
23-
- name: Install asdf
24-
uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
25-
with:
26-
asdf_branch: v0.14.1
27-
28-
- name: Cache asdf
29-
uses: actions/cache@v4
30-
with:
31-
path: |
32-
~/.asdf
33-
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
34-
restore-keys: |
35-
${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
36-
37-
- name: Install asdf dependencies in .tool-versions
38-
uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
39-
with:
40-
asdf_branch: v0.14.1
41-
42-
- name: Install dependencies
43-
run: |
44-
make install
45-
46-
- name: Set VERSION_TAG to be next tag varsion
47-
id: output_version_tag
48-
run: |
49-
NEXT_VERSION=$(npx semantic-release --dry-run | grep -i 'The next release version is' | sed -E 's/.* ([[:digit:].]+)$/\1/')
50-
tagFormat=$(node -e "const config=require('./release.config.js'); console.log(config.tagFormat)")
51-
if [ "${tagFormat}" = "null" ]
52-
then
53-
tagFormat="v\${version}"
54-
fi
55-
# disabling shellcheck as replace does not work
56-
# shellcheck disable=SC2001
57-
VERSION_TAG=$(echo "$tagFormat" | sed "s/\${version}/$NEXT_VERSION/")
58-
echo "## VERSION TAG : ${VERSION_TAG}" >> "$GITHUB_STEP_SUMMARY"
59-
echo "VERSION_TAG=${VERSION_TAG}" >> "$GITHUB_OUTPUT"
60-
echo "VERSION_TAG=${VERSION_TAG}" >> "$GITHUB_ENV"
61-
env:
62-
GITHUB_TOKEN: ${{ github.token }}
6319

64-
- name: tag release
65-
env:
66-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
- name: Get asdf version
21+
id: asdf-version
22+
run: echo "version=$(awk '!/^#/ && NF {print $1; exit}' .tool-versions.asdf)" >> "$GITHUB_OUTPUT"
23+
- name: Load config value
24+
id: load-config
6725
run: |
68-
npx semantic-release
69-
70-
- name: Get release for editing
71-
id: get_release
72-
# version 1.2.4
73-
uses: cardinalby/git-get-release-action@5172c3a026600b1d459b117738c605fabc9e4e44
74-
env:
75-
GITHUB_TOKEN: ${{ github.token }}
76-
with:
77-
tag: ${{ env.VERSION_TAG }}
78-
79-
- name: Edit Release
80-
# version 1.2.0
81-
uses: irongut/EditRelease@ccf529ad26dddf9996e7dd0f24ca5da4ea507cc2
82-
with:
83-
token: ${{ secrets.GITHUB_TOKEN }}
84-
id: ${{ steps.get_release.outputs.id }}
85-
body: |
86-
## Info
87-
[See code diff](${{ github.event.compare }})
88-
[Release workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
89-
90-
It was initialized by [${{ github.event.sender.login }}](${{ github.event.sender.html_url }})
26+
TAG_FORMAT=$(yq '.TAG_FORMAT' .github/config/settings.yml)
27+
echo "TAG_FORMAT=$TAG_FORMAT" >> "$GITHUB_OUTPUT"
28+
quality_checks:
29+
needs: [get_asdf_version]
30+
uses: ./.github/workflows/quality-checks.yml
31+
with:
32+
asdfVersion: ${{ needs.get_asdf_version.outputs.asdf_version }}
33+
secrets:
34+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
35+
tag_release:
36+
needs: [quality_checks, get_asdf_version]
37+
uses: NHSDigital/eps-workflow-semantic-release/.github/workflows/tag-release.yml@f80157cecce288dd175e61b477a1d2dbe9c88b99
38+
with:
39+
dry_run: false
40+
asdfVersion: ${{ needs.get_asdf_version.outputs.asdf_version }}
41+
branch_name: main
42+
publish_package: false
43+
tag_format: ${{ needs.get_asdf_version.outputs.tag_format }}
44+
secrets: inherit

0 commit comments

Comments
 (0)