Skip to content

Commit fbfafa9

Browse files
authored
feat(github-actions): enable various imperative github actions (#847)
## Introduction ✏️ Ensure various imperative pipelines are available for consistent pipeline actions across all the applications. ## Resolution ✔️ * Added `github.yml` for PR lint check. * Added `prettier:all` check to `lint.yml`. * Added `pr.yml` check for stale PR validation. * Updated `publish.yml` as per latest `Google Release please` release notes. ## Miscellaneous ➕ * Dependencies updates * Moved GHA hardcoded variables to Enterprise scope GH secrets / variable * Refactored GitHooks --------- Co-authored-by: Abhi Markan <amarkan@ukexportfinance.gov.uk>
1 parent 93a9a91 commit fbfafa9

File tree

13 files changed

+292
-56
lines changed

13 files changed

+292
-56
lines changed

.github/workflows/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ on:
3939
env:
4040
PRODUCT: apim
4141
ENVIRONMENT: ${{ github.ref_name }}
42-
TIMEZONE: "Europe/London"
42+
timezone: ${{ vars.TIMEZONE }}
4343
# Base artifact
4444
FROM: latest
4545

.github/workflows/github.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This GitHub Actions workflow ensures that any pull request targeting the main or main-*
2+
# branches meets certain criteria before it is merged. The workflow sets up the necessary infrastructure,
3+
# configures the environment, and performs checks on the pull request title, body, labels
4+
# and assignee to ensure that it adheres to predefined standards. If any of these checks fail,
5+
# the workflow will exit with an error, preventing the pull request from proceeding.
6+
7+
name: GitHub
8+
run-name: 🔬 Pull request inspection on ${{ github.event.number }}
9+
10+
on:
11+
pull_request:
12+
branches: [main, main-*]
13+
14+
env:
15+
environment: "qa"
16+
timezone: ${{ vars.TIMEZONE }}
17+
18+
jobs:
19+
# 1. Setup test infrastructure
20+
setup:
21+
name: Infrastructure setup 🔧
22+
runs-on: ubuntu-latest
23+
outputs:
24+
environment: ${{ env.environment }}
25+
timezone: ${{ env.timezone }}
26+
steps:
27+
- name: Environment 🧪
28+
run: echo "Environment set to ${{ env.environment }}"
29+
30+
- name: Timezone 🌐
31+
run: echo "Timezone set to ${{ env.timezone }}"
32+
33+
# 2. Pull request
34+
pullrequest:
35+
name: Pull request ⬇️
36+
needs: setup
37+
environment:
38+
name: ${{ needs.setup.outputs.environment }}
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Timezone
42+
uses: szenius/set-timezone@v1.2
43+
with:
44+
timezoneLinux: ${{ needs.setup.outputs.timezone }}
45+
46+
- name: Repository
47+
uses: actions/checkout@v4
48+
49+
- name: Node
50+
uses: actions/setup-node@v4
51+
with:
52+
node-version: ${{ vars.NODE_VERSION }}
53+
54+
- name: Dependencies
55+
working-directory: ./
56+
run: npm ci --legacy-peer-deps
57+
58+
- name: Title
59+
run: echo "${{ github.event.pull_request.title }}" | npx commitlint --color --verbose $1
60+
61+
- name: Body
62+
if: ${{ github.event.pull_request.body == '' }}
63+
run: exit 1
64+
65+
- name: Label
66+
if: ${{ github.event.pull_request.labels == '[]' }}
67+
run: exit 1
68+
69+
- name: Assignee
70+
if: ${{ github.event.pull_request.assignee == '[]' }}
71+
run: exit 1

.github/workflows/infrastructure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ on:
6868
env:
6969
PRODUCT: apim
7070
ENVIRONMENT: infrastructure
71-
TIMEZONE: "Europe/London"
71+
timezone: ${{ vars.TIMEZONE }}
7272
# Deployment environment target i.e., `dev`, `staging`, `production`
7373
TARGET: ${{ vars.ENVIRONMENT }}
7474

.github/workflows/lint.yml

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
1-
# MDM-API Git Hub Actions
2-
#####################################
3-
# This GHA is responsible for initiating linting checks
1+
# Workflow Name: Lint
2+
# Trigger: Pull requests to the main branch that modify specific files (listed in paths).
3+
#
4+
# Environment:
5+
# environment: set to dev
6+
# timezone: retrieved from vars.TIMEZONE
7+
#
8+
# Setup Test Infrastructure:
9+
# Name: Infrastructure setup
10+
# Runs on: ubuntu-latest
11+
# Outputs environment and timezone variables for use in subsequent jobs.
12+
# Steps:
13+
# Echoes the environment and timezone for verification.
14+
#
15+
# Lint:
16+
# Name: Scanning
17+
# Depends on: setup
18+
# Runs on: ubuntu-latest
19+
# Steps:
20+
# Sets the timezone using the specified value.
21+
# Checks out the repository code.
22+
# Sets up the specified Node.js version.
23+
# Installs dependencies using npm run ci:all.
24+
# Runs linting using the command npm run lint
25+
#
26+
# Prettier:
27+
# Name: Prettier
28+
# Depends on: setup
29+
# Runs on: ubuntu-latest
30+
# Steps:
31+
# Sets the timezone using the specified value.
32+
# Checks out the repository code.
33+
# Sets up the specified Node.js version.
34+
# Installs dependencies using npm run ci:all.
35+
# Runs prettier using the command npm run prettier.
36+
#
37+
# Key Points:
38+
# The workflow focuses on linting, which checks code for potential errors, style issues, and adherence to best practices.
39+
# It uses a sequential structure, with the linting job depending on the setup job.
40+
# Environment variables are shared between jobs for consistency.
41+
# The workflow leverages actions from the GitHub Marketplace for setting the timezone and installing Node.js.
42+
#
443

5-
name: Quality Assurance - Lint
6-
run-name: Executing lint QA on ${{ github.repository }} 🚀
44+
name: Lint
45+
run-name: 🎨 Lint checking on ${{ github.event.number }}
746

847
on:
948
pull_request:
@@ -14,8 +53,7 @@ on:
1453

1554
env:
1655
environment: "qa"
17-
timezone: "Europe/London"
18-
node: ${{ vars.NODE_VERSION }}
56+
timezone: ${{ vars.TIMEZONE }}
1957

2058
jobs:
2159
# 1. Setup test infrastructure
@@ -40,17 +78,17 @@ jobs:
4078
runs-on: ubuntu-latest
4179
steps:
4280
- name: Timezone
43-
uses: szenius/set-timezone@v2.0
81+
uses: szenius/set-timezone@v1.2
4482
with:
4583
timezoneLinux: ${{ needs.setup.outputs.timezone }}
4684

4785
- name: Repository
4886
uses: actions/checkout@v4
4987

5088
- name: Node
51-
uses: actions/setup-node@v4
89+
uses: actions/setup-node@v3
5290
with:
53-
node-version: ${{ env.node }}
91+
node-version: ${{ vars.NODE_VERSION }}
5492

5593
- name: Dependencies
5694
working-directory: ./
@@ -59,3 +97,31 @@ jobs:
5997
- name: Linting
6098
working-directory: ./
6199
run: npm run lint
100+
101+
# 3. Prettier
102+
prettier:
103+
name: Prettier 🎨
104+
environment:
105+
name: ${{ needs.setup.outputs.environment }}
106+
runs-on: ubuntu-latest
107+
steps:
108+
- name: Timezone
109+
uses: szenius/set-timezone@v1.2
110+
with:
111+
timezoneLinux: ${{ needs.setup.outputs.timezone }}
112+
113+
- name: Repository
114+
uses: actions/checkout@v4
115+
116+
- name: Node
117+
uses: actions/setup-node@v3
118+
with:
119+
node-version: ${{ vars.NODE_VERSION }}
120+
121+
- name: Dependencies
122+
working-directory: ./
123+
run: npm ci --legacy-peer-deps
124+
125+
- name: Linting
126+
working-directory: ./
127+
run: npm run prettier

.github/workflows/pr.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This YAML configuration defines a GitHub Actions workflow named "PR" designed to analyse pull requests
2+
# for staleness and take action accordingly.
3+
#
4+
# Identify: Uses the actions/stale@v5 action with parameters to mark pull requests as stale if
5+
# they have been inactive for a certain number of days and close them if they exceed another threshold.
6+
# This workflow helps maintain the health of the pull request queue by identifying and managing stale pull requests automatically.
7+
#
8+
9+
name: PR
10+
run-name: 🔎 Pull request analysis on ${{ github.event.number }}
11+
12+
on:
13+
schedule:
14+
- cron: "00 00 * * *"
15+
env:
16+
environment: "qa"
17+
timezone: ${{ vars.TIMEZONE }}
18+
19+
jobs:
20+
# 1. Setup test infrastructure
21+
setup:
22+
name: Infrastructure setup 🔧
23+
runs-on: ubuntu-latest
24+
outputs:
25+
environment: ${{ env.environment }}
26+
timezone: ${{ env.timezone }}
27+
steps:
28+
- name: Environment 🧪
29+
run: echo "Environment set to ${{ env.environment }}"
30+
31+
- name: Timezone 🌐
32+
run: echo "Timezone set to ${{ env.timezone }}"
33+
34+
# 2. Identify stale PRs
35+
stale:
36+
name: Stale 📅
37+
needs: setup
38+
environment:
39+
name: ${{ needs.setup.outputs.environment }}
40+
runs-on: ubuntu-latest
41+
permissions:
42+
pull-requests: write
43+
44+
steps:
45+
- name: Identify
46+
uses: actions/stale@v9
47+
with:
48+
days-before-pr-stale: ${{ vars.STALE_PR_DAYS }}
49+
stale-pr-message: "Pull request marked as stale due to inactivity."
50+
stale-pr-label: "Stale"
51+
days-before-pr-close: ${{ vars.CLOSE_PR_DAYS }}
52+
close-pr-message: "Pull request has been closed due to inactivity."
53+
close-pr-label: "Closed"

.github/workflows/publish.yml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# MDM-API Git Hub Actions
1+
# MDM Git Hub Actions
22
#####################################
3-
# This GHA is responsible for release version updates.
3+
# This GHA is responsible for creating automated
4+
# GitHub release based PRs. Once the PR is merged,
5+
# Google Release Please will update the `CHANGELOG.md`,
6+
# `README.md` and `package.json` files, followed by
7+
# tagging the commit with the appropriate version
8+
# number (as per SemVer) and creating a GitHub tag for the release.
49

510
name: Automated release
611
run-name: Executing release on ${{ github.repository }} 🚀
@@ -14,13 +19,36 @@ permissions:
1419
pull-requests: write
1520

1621
jobs:
17-
# 1. `package.json`, `README.md` and `CHANGELOG.md` updates
22+
# 1. Setup test infrastructure
23+
setup:
24+
name: Infrastructure setup 🔧
25+
runs-on: ubuntu-latest
26+
outputs:
27+
environment: ${{ env.environment }}
28+
timezone: ${{ env.timezone }}
29+
steps:
30+
- name: Environment 🧪
31+
run: echo "Environment set to ${{ env.environment }}"
32+
33+
- name: Timezone 🌐
34+
run: echo "Timezone set to ${{ env.timezone }}"
35+
36+
# 2. Update files
1837
release:
19-
name: Release setup 🔧
38+
name: Release ✨
39+
needs: setup
40+
environment:
41+
name: ${{ needs.setup.outputs.environment }}
2042
runs-on: ubuntu-latest
43+
2144
steps:
22-
- name: Release version ⚡️
23-
uses: google-github-actions/release-please-action@v4
24-
with:
25-
token: ${{ secrets.RELEASE_TOKEN }}
26-
release-type: node
45+
- name: Repository
46+
uses: actions/checkout@v4
47+
48+
- name: Dependencies
49+
working-directory: ./
50+
run: npm ci
51+
52+
- name: Create
53+
working-directory: ./
54+
run: npx release-please release-pr --token=${{ secrets.RELEASE_TOKEN }} --repo-url=https://github.com/${{ github.repository }} --release-type=node

.github/workflows/sca.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515

1616
env:
1717
environment: "qa"
18-
timezone: "Europe/London"
18+
timezone: ${{ vars.TIMEZONE }}
1919

2020
jobs:
2121
# 1. Setup test infrastructure

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ on:
1616

1717
env:
1818
environment: "qa"
19-
timezone: "Europe/London"
20-
node: ${{ vars.NODE_VERSION }}
19+
timezone: ${{ vars.TIMEZONE }}
2120

2221
jobs:
2322
# 1. Setup test infrastructure
@@ -53,7 +52,7 @@ jobs:
5352
- name: Node
5453
uses: actions/setup-node@v4
5554
with:
56-
node-version: ${{ env.node }}
55+
node-version: ${{ vars.NODE_VERSION }}
5756

5857
- name: Dependencies
5958
working-directory: ./

.husky/commit-msg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx commitlint --edit $1
5-
npx lint-staged
4+
npx commitlint --color --edit $1

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

0 commit comments

Comments
 (0)