Skip to content

Commit

Permalink
feat(github-actions): enable various imperative github actions (#847)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
abhi-markan and abhi-markan authored May 17, 2024
1 parent 93a9a91 commit fbfafa9
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on:
env:
PRODUCT: apim
ENVIRONMENT: ${{ github.ref_name }}
TIMEZONE: "Europe/London"
timezone: ${{ vars.TIMEZONE }}
# Base artifact
FROM: latest

Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This GitHub Actions workflow ensures that any pull request targeting the main or main-*
# branches meets certain criteria before it is merged. The workflow sets up the necessary infrastructure,
# configures the environment, and performs checks on the pull request title, body, labels
# and assignee to ensure that it adheres to predefined standards. If any of these checks fail,
# the workflow will exit with an error, preventing the pull request from proceeding.

name: GitHub
run-name: 🔬 Pull request inspection on ${{ github.event.number }}

on:
pull_request:
branches: [main, main-*]

env:
environment: "qa"
timezone: ${{ vars.TIMEZONE }}

jobs:
# 1. Setup test infrastructure
setup:
name: Infrastructure setup 🔧
runs-on: ubuntu-latest
outputs:
environment: ${{ env.environment }}
timezone: ${{ env.timezone }}
steps:
- name: Environment 🧪
run: echo "Environment set to ${{ env.environment }}"

- name: Timezone 🌐
run: echo "Timezone set to ${{ env.timezone }}"

# 2. Pull request
pullrequest:
name: Pull request ⬇️
needs: setup
environment:
name: ${{ needs.setup.outputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Timezone
uses: szenius/[email protected]
with:
timezoneLinux: ${{ needs.setup.outputs.timezone }}

- name: Repository
uses: actions/checkout@v4

- name: Node
uses: actions/setup-node@v4
with:
node-version: ${{ vars.NODE_VERSION }}

- name: Dependencies
working-directory: ./
run: npm ci --legacy-peer-deps

- name: Title
run: echo "${{ github.event.pull_request.title }}" | npx commitlint --color --verbose $1

- name: Body
if: ${{ github.event.pull_request.body == '' }}
run: exit 1

- name: Label
if: ${{ github.event.pull_request.labels == '[]' }}
run: exit 1

- name: Assignee
if: ${{ github.event.pull_request.assignee == '[]' }}
run: exit 1
2 changes: 1 addition & 1 deletion .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ on:
env:
PRODUCT: apim
ENVIRONMENT: infrastructure
TIMEZONE: "Europe/London"
timezone: ${{ vars.TIMEZONE }}
# Deployment environment target i.e., `dev`, `staging`, `production`
TARGET: ${{ vars.ENVIRONMENT }}

Expand Down
86 changes: 76 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
# MDM-API Git Hub Actions
#####################################
# This GHA is responsible for initiating linting checks
# Workflow Name: Lint
# Trigger: Pull requests to the main branch that modify specific files (listed in paths).
#
# Environment:
# environment: set to dev
# timezone: retrieved from vars.TIMEZONE
#
# Setup Test Infrastructure:
# Name: Infrastructure setup
# Runs on: ubuntu-latest
# Outputs environment and timezone variables for use in subsequent jobs.
# Steps:
# Echoes the environment and timezone for verification.
#
# Lint:
# Name: Scanning
# Depends on: setup
# Runs on: ubuntu-latest
# Steps:
# Sets the timezone using the specified value.
# Checks out the repository code.
# Sets up the specified Node.js version.
# Installs dependencies using npm run ci:all.
# Runs linting using the command npm run lint
#
# Prettier:
# Name: Prettier
# Depends on: setup
# Runs on: ubuntu-latest
# Steps:
# Sets the timezone using the specified value.
# Checks out the repository code.
# Sets up the specified Node.js version.
# Installs dependencies using npm run ci:all.
# Runs prettier using the command npm run prettier.
#
# Key Points:
# The workflow focuses on linting, which checks code for potential errors, style issues, and adherence to best practices.
# It uses a sequential structure, with the linting job depending on the setup job.
# Environment variables are shared between jobs for consistency.
# The workflow leverages actions from the GitHub Marketplace for setting the timezone and installing Node.js.
#

name: Quality Assurance - Lint
run-name: Executing lint QA on ${{ github.repository }} 🚀
name: Lint
run-name: 🎨 Lint checking on ${{ github.event.number }}

on:
pull_request:
Expand All @@ -14,8 +53,7 @@ on:

env:
environment: "qa"
timezone: "Europe/London"
node: ${{ vars.NODE_VERSION }}
timezone: ${{ vars.TIMEZONE }}

jobs:
# 1. Setup test infrastructure
Expand All @@ -40,17 +78,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Timezone
uses: szenius/set-timezone@v2.0
uses: szenius/set-timezone@v1.2
with:
timezoneLinux: ${{ needs.setup.outputs.timezone }}

- name: Repository
uses: actions/checkout@v4

- name: Node
uses: actions/setup-node@v4
uses: actions/setup-node@v3
with:
node-version: ${{ env.node }}
node-version: ${{ vars.NODE_VERSION }}

- name: Dependencies
working-directory: ./
Expand All @@ -59,3 +97,31 @@ jobs:
- name: Linting
working-directory: ./
run: npm run lint

# 3. Prettier
prettier:
name: Prettier 🎨
environment:
name: ${{ needs.setup.outputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Timezone
uses: szenius/[email protected]
with:
timezoneLinux: ${{ needs.setup.outputs.timezone }}

- name: Repository
uses: actions/checkout@v4

- name: Node
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}

- name: Dependencies
working-directory: ./
run: npm ci --legacy-peer-deps

- name: Linting
working-directory: ./
run: npm run prettier
53 changes: 53 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This YAML configuration defines a GitHub Actions workflow named "PR" designed to analyse pull requests
# for staleness and take action accordingly.
#
# Identify: Uses the actions/stale@v5 action with parameters to mark pull requests as stale if
# they have been inactive for a certain number of days and close them if they exceed another threshold.
# This workflow helps maintain the health of the pull request queue by identifying and managing stale pull requests automatically.
#

name: PR
run-name: 🔎 Pull request analysis on ${{ github.event.number }}

on:
schedule:
- cron: "00 00 * * *"
env:
environment: "qa"
timezone: ${{ vars.TIMEZONE }}

jobs:
# 1. Setup test infrastructure
setup:
name: Infrastructure setup 🔧
runs-on: ubuntu-latest
outputs:
environment: ${{ env.environment }}
timezone: ${{ env.timezone }}
steps:
- name: Environment 🧪
run: echo "Environment set to ${{ env.environment }}"

- name: Timezone 🌐
run: echo "Timezone set to ${{ env.timezone }}"

# 2. Identify stale PRs
stale:
name: Stale 📅
needs: setup
environment:
name: ${{ needs.setup.outputs.environment }}
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Identify
uses: actions/stale@v9
with:
days-before-pr-stale: ${{ vars.STALE_PR_DAYS }}
stale-pr-message: "Pull request marked as stale due to inactivity."
stale-pr-label: "Stale"
days-before-pr-close: ${{ vars.CLOSE_PR_DAYS }}
close-pr-message: "Pull request has been closed due to inactivity."
close-pr-label: "Closed"
46 changes: 37 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# MDM-API Git Hub Actions
# MDM Git Hub Actions
#####################################
# This GHA is responsible for release version updates.
# This GHA is responsible for creating automated
# GitHub release based PRs. Once the PR is merged,
# Google Release Please will update the `CHANGELOG.md`,
# `README.md` and `package.json` files, followed by
# tagging the commit with the appropriate version
# number (as per SemVer) and creating a GitHub tag for the release.

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

jobs:
# 1. `package.json`, `README.md` and `CHANGELOG.md` updates
# 1. Setup test infrastructure
setup:
name: Infrastructure setup 🔧
runs-on: ubuntu-latest
outputs:
environment: ${{ env.environment }}
timezone: ${{ env.timezone }}
steps:
- name: Environment 🧪
run: echo "Environment set to ${{ env.environment }}"

- name: Timezone 🌐
run: echo "Timezone set to ${{ env.timezone }}"

# 2. Update files
release:
name: Release setup 🔧
name: Release ✨
needs: setup
environment:
name: ${{ needs.setup.outputs.environment }}
runs-on: ubuntu-latest

steps:
- name: Release version ⚡️
uses: google-github-actions/release-please-action@v4
with:
token: ${{ secrets.RELEASE_TOKEN }}
release-type: node
- name: Repository
uses: actions/checkout@v4

- name: Dependencies
working-directory: ./
run: npm ci

- name: Create
working-directory: ./
run: npx release-please release-pr --token=${{ secrets.RELEASE_TOKEN }} --repo-url=https://github.com/${{ github.repository }} --release-type=node
2 changes: 1 addition & 1 deletion .github/workflows/sca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

env:
environment: "qa"
timezone: "Europe/London"
timezone: ${{ vars.TIMEZONE }}

jobs:
# 1. Setup test infrastructure
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ on:

env:
environment: "qa"
timezone: "Europe/London"
node: ${{ vars.NODE_VERSION }}
timezone: ${{ vars.TIMEZONE }}

jobs:
# 1. Setup test infrastructure
Expand Down Expand Up @@ -53,7 +52,7 @@ jobs:
- name: Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.node }}
node-version: ${{ vars.NODE_VERSION }}

- name: Dependencies
working-directory: ./
Expand Down
3 changes: 1 addition & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit $1
npx lint-staged
npx commitlint --color --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
21 changes: 17 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Root
node_modules/
dist/
.cache/
build/
public/
generated_reports/
coverage/
package*.json
.cache

# Sub-directories
**/node_modules/
**/dist/
**/build/
**/public/
**/generated_reports/
**/coverage/
**/node_modules/**
/node_modules
/package-lock.json
**/package*.json
**/.cache
Loading

0 comments on commit fbfafa9

Please sign in to comment.