Skip to content

Commit

Permalink
test: DAH-2084 Implement Github Actions (#2467)
Browse files Browse the repository at this point in the history
* test: PR Title linter

* improvements

* add linter to template

* translations action

* Improvments

* Test change

* Test change on tl

* run grunt translations

* ignore whitespace

* Test change

* revert

* zh test change

* revert zh change

* run on pull request
  • Loading branch information
chadbrokaw authored Jan 3, 2025
1 parent ebb5d01 commit 9fccb0e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ https://sfgovdt.jira.com/browse/<JIRA TICKET NUMBER>

- [ ] branch name begins with `angular` if it contains updates to Angular code
- [ ] branch name contains the Jira ticket number
- [ ] PR name follows `type: TICKET-NUMBER Description` format, e.g. `feat: DAH-123 New Feature`
- [ ] PR name follows `type: TICKET-NUMBER Description` format, e.g. `feat: DAH-123 New Feature`. If the PR is urgent and does not need a ticket then use the format `urgent: Description`

### Code quality

Expand All @@ -32,4 +32,4 @@ https://sfgovdt.jira.com/browse/<JIRA TICKET NUMBER>

- [ ] PR has `needs review` label
- [ ] Use `Housing Eng` group to automatically assign reviewers, and/or assign specific engineers
- [ ] If time sensitive, notify engineers in Slack
- [ ] If time sensitive, notify engineers in Slack
47 changes: 47 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Validate PR Title

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Validate PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
# Define the regex for the required formats
jira_regex="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test): DAH-[0-9]+ .+"
urgent_regex="^urgent: \S+"
if [[ "${PR_TITLE}" =~ $urgent_regex ]]; then
echo "PR title contains 'urgent'. Skipping JIRA check but validating description."
elif [[ "${PR_TITLE}" =~ $jira_regex ]]; then
echo "PR title matches JIRA format."
exit 0
else
echo "Invalid PR title: '${PR_TITLE}'"
echo "Please format your PR title as:"
echo "'<label>: DAH-<issue number> <description>'"
echo "or use 'urgent: <description>' for urgent PRs."
echo "Available labels (case sensitive): build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test."
echo "Examples:"
echo "- 'feat: DAH-1234 Add new feature'"
echo "- 'urgent: Hotfix for production'"
exit 1
fi
# Validate that a description exists and has no trailing whitespace
description_regex="^.*: \S+"
if [[ ! "${PR_TITLE}" =~ $description_regex ]]; then
echo "Missing or invalid description in PR title: '${PR_TITLE}'"
echo "Ensure your PR title includes a description after the colon with no extra whitespace."
exit 1
fi
echo "PR title is valid."
49 changes: 49 additions & 0 deletions .github/workflows/translations-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Check Translation Files Sorting

on:
pull_request:
paths:
- "app/assets/json/translations/react/*.json"

jobs:
check-sorting:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Verify jq installation
run: |
if ! command -v jq &> /dev/null; then
echo "jq could not be found, installing..."
sudo apt-get update && sudo apt-get install -y jq
else
echo "jq is already installed: $(jq --version)"
fi
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Install dependencies
run: npm install --global jsonlint-cli

- name: Validate and check sorting of translation files
run: |
for file in app/assets/json/translations/react/*.json; do
echo "Checking $file"
jsonlint-cli $file
jq -S '.' $file > sorted.json
if ! diff -uw $file sorted.json > differences.txt; then
echo "Sorting errors found in $file:"
cat differences.txt
rm sorted.json differences.txt
exit 1
else
echo "$file is properly sorted."
rm sorted.json
fi
done

0 comments on commit 9fccb0e

Please sign in to comment.