Skip to content

Commit

Permalink
fix: fixed broken test steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Eezi committed Jan 6, 2025
2 parents 7419136 + 50dfe18 commit ca92386
Show file tree
Hide file tree
Showing 232 changed files with 30,546 additions and 13,146 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'cypress'],
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:cypress/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'prettier'
],
Expand Down
197 changes: 132 additions & 65 deletions .github/workflows/auto-pr-to-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,100 @@ on:
description: 'PR number to process'
required: true
default: ''
dry_run:
description: 'Dry run'
required: false
default: false
type: boolean

jobs:
create-pr:
resolve-releases:
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.resolve-applicable-versions.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get PR details from workflow dispatch
if: ${{ github.event_name == 'workflow_dispatch' }}
id: get_pr_details_dispatch
run: |
PR_NUMBER=${{ github.event.inputs.pr_number }}
PR_DATA=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/opencrvs/opencrvs-countryconfig/pulls/$PR_NUMBER)
echo "MILESTONE=$(printf '%s' $PR_DATA | jq -r '.milestone.title')" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Get PR details from event
if: ${{ github.event_name == 'pull_request' }}
id: get_pr_details_event
run: |
echo "MILESTONE=${{ github.event.pull_request.milestone.title }}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Check for milestone and if release branch exists
continue-on-error: true
id: resolve-applicable-versions
run: |
if [ -z "${{ env.MILESTONE }}" ] || [ "${{ env.MILESTONE }}" = "null" ]; then
echo "No milestone set. Exiting."
exit 1
fi
filter_versions() {
local input_version=$1
# List remote branches, extract versions, and sort them semantically
versions=$(git ls-remote --heads origin 'release-*' | awk -F'release-' '{print $2}' | sort -V)
# Filter out versions less than the input version
filtered_versions=$(echo "$versions" | awk -v input="$input_version" '
function compare_versions(v1, v2) {
split(v1, a, /[.v]/);
split(v2, b, /[.v]/);
for (i = 2; i <= 4; i++) {
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return 1;
}
return 0;
}
{
if (compare_versions($0, input) >= 0) {
print $0
}
}')
# Keep only the highest patch version for each minor version
echo "$filtered_versions" | awk -F. '
{
minor = $1 "." $2;
patches[minor] = $0;
}
END {
for (minor in patches) {
print patches[minor];
}
}' | sort -V
}
versions=$(filter_versions "${{ env.MILESTONE }}")
json_array=$(echo "$versions" | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "matrix=$json_array" >> $GITHUB_OUTPUT
create-pr:
needs: resolve-releases
runs-on: ubuntu-22.04
if: ${{ always() && needs.resolve-releases.result == 'success' }}

strategy:
fail-fast: false
matrix:
version: ${{fromJson(needs.resolve-releases.outputs.matrix)}}

steps:
- name: Checkout repository
Expand All @@ -33,21 +122,18 @@ jobs:
id: get_pr_details_dispatch
run: |
PR_NUMBER=${{ github.event.inputs.pr_number }}
PR_DATA=$(gh pr view $PR_NUMBER --json number,headRefName,baseRefName,mergedBy,mergeCommit,author,milestone,title --jq '{number: .number, headRefName: .headRefName, baseRefName: .baseRefName, merger: .mergedBy.login, author: .author.login, milestone: .milestone.title, title: .title}')
echo "PR_ID=$(echo $PR_DATA | jq -r '.number')" >> $GITHUB_ENV
echo "PR_AUTHOR=$(echo $PR_DATA | jq -r '.author')" >> $GITHUB_ENV
echo "PR_MERGER=$(echo $PR_DATA | jq -r '.merger')" >> $GITHUB_ENV
echo "MILESTONE=$(echo $PR_DATA | jq -r '.milestone')" >> $GITHUB_ENV
echo "BASE_BRANCH=$(echo $PR_DATA | jq -r '.baseRefName')" >> $GITHUB_ENV
echo "HEAD_BRANCH=$(echo $PR_DATA | jq -r '.headRefName')" >> $GITHUB_ENV
echo "PR_TITLE=$(echo $PR_DATA | jq -r '.title')" >> $GITHUB_ENV
LATEST_COMMIT_SHA=$(gh pr view $PR_NUMBER --json commits --jq '.commits[-1].oid')
FIRST_COMMIT_SHA=$(gh pr view $PR_NUMBER --json commits --jq '.commits[0].oid')
echo "LATEST_COMMIT_SHA=${LATEST_COMMIT_SHA}" >> $GITHUB_ENV
echo "FIRST_COMMIT_SHA=${FIRST_COMMIT_SHA}" >> $GITHUB_ENV
PR_DATA=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/opencrvs/opencrvs-countryconfig/pulls/$PR_NUMBER)
# printf escapes the newlines in the JSON, so we can use jq to parse output such as:
# "body": "![image](https://github.com/user-attachments/assets/8eee5bcf-7692-490f-a19f-576623e09961)\r\n",
echo "PR_ID=$(printf '%s' $PR_DATA | jq -r '.number')" >> $GITHUB_ENV
echo "PR_AUTHOR=$(printf '%s' $PR_DATA | jq -r '.user.login')" >> $GITHUB_ENV
echo "PR_MERGER=$(printf '%s' $PR_DATA | jq -r '.merged_by.login')" >> $GITHUB_ENV
echo "BASE_BRANCH=$(printf '%s' $PR_DATA | jq -r '.base.ref')" >> $GITHUB_ENV
echo "HEAD_BRANCH=$(printf '%s' $PR_DATA | jq -r '.head.ref')" >> $GITHUB_ENV
echo "PR_TITLE=$(printf '%s' $PR_DATA | jq -r '.title')" >> $GITHUB_ENV
echo "BASE_SHA=$(printf '%s' $PR_DATA | jq -r '.base.sha')" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Get PR details from event
if: ${{ github.event_name == 'pull_request' }}
Expand All @@ -56,85 +142,64 @@ jobs:
PR_NUMBER=${{ github.event.pull_request.number }}
echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "PR_AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
echo "MILESTONE=${{ github.event.pull_request.milestone.title }}" >> $GITHUB_ENV
echo "BASE_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
echo "HEAD_BRANCH=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
echo "PR_TITLE=${{ github.event.pull_request.title }}" >> $GITHUB_ENV
LATEST_COMMIT_SHA=$(gh pr view $PR_NUMBER --json commits --jq '.commits[-1].oid')
FIRST_COMMIT_SHA=$(gh pr view $PR_NUMBER --json commits --jq '.commits[0].oid')
echo "LATEST_COMMIT_SHA=${LATEST_COMMIT_SHA}" >> $GITHUB_ENV
echo "FIRST_COMMIT_SHA=${FIRST_COMMIT_SHA}" >> $GITHUB_ENV
echo "BASE_SHA=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
PR_DETAILS=$(gh pr view $PR_NUMBER --json mergedBy)
MERGED_BY_LOGIN=$(echo "$PR_DETAILS" | jq -r '.mergedBy.login')
echo "PR_MERGER=$MERGED_BY_LOGIN" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check for milestone and if release branch exists
id: check_release_branch
run: |
if [ -z "${{ env.MILESTONE }}" ]; then
echo "No milestone set. Exiting."
exit 0
fi
RELEASE_BRANCH="release-${{ env.MILESTONE }}"
# Check if the release branch exists
if git ls-remote --heads origin $RELEASE_BRANCH | grep -q "refs/heads/$RELEASE_BRANCH"; then
echo "RELEASE_BRANCH=${RELEASE_BRANCH}" >> $GITHUB_ENV
else
echo "Release branch $RELEASE_BRANCH does not exist. Exiting."
exit 0
fi
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Create and push the new branch for the PR
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
SEMANTIC_PR_TITLE="${{ env.PR_TITLE }}"
RELEASE_BRANCH="release-${{ matrix.version }}"
MILESTONE="${{ matrix.version }}"
# Check for semantic prefix
if [[ $SEMANTIC_PR_TITLE =~ ^(feat|fix|docs|style|refactor|perf|test|chore|build|ci|revert|wip|merge)\: ]]; then
SEMANTIC_PR_TITLE="${BASH_REMATCH[1]}(${MILESTONE}): ${SEMANTIC_PR_TITLE#*: }"
else
SEMANTIC_PR_TITLE="🍒 Merge changes from PR #${{ env.PR_ID }} to ${{ env.RELEASE_BRANCH }}"
SEMANTIC_PR_TITLE="🍒 Merge changes from PR #${{ env.PR_ID }} to $RELEASE_BRANCH"
fi
PR_BODY="Automated PR to merge changes from develop to ${{ env.RELEASE_BRANCH }}"
PR_BODY="Automated PR to merge changes from develop to $RELEASE_BRANCH"
# Configure git
git config user.name "github-actions"
git config user.email "[email protected]"
git config advice.mergeConflict false
# Fetch and checkout the release branch
git fetch --all
git checkout ${{ env.RELEASE_BRANCH }}
git fetch --all --unshallow
git checkout $RELEASE_BRANCH
# Create a new branch for the PR
NEW_BRANCH="auto-pr-${{ env.RELEASE_BRANCH }}-${{ env.PR_ID }}-$RANDOM"
NEW_BRANCH="auto-pr-$RELEASE_BRANCH-${{ env.PR_ID }}-$RANDOM"
git checkout -b $NEW_BRANCH
echo "First commit: ${{ env.FIRST_COMMIT_SHA }}"
echo "Latest commit: ${{ env.LATEST_COMMIT_SHA }}"
# NOTE: git cherry-pick range needs ~ to include the FIRST_COMMIT_SHA (https://stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-them-into-another-branch)
COMMIT_RANGE="${{ env.FIRST_COMMIT_SHA }}~..${{ env.LATEST_COMMIT_SHA }}"
echo "HEAD_BRANCH: ${{ env.HEAD_BRANCH }}"
echo "BASE_SHA: ${{ env.BASE_SHA }}"
if [ "${{ env.FIRST_COMMIT_SHA }}" == "${{ env.LATEST_COMMIT_SHA }}" ]; then
COMMIT_RANGE=${{ env.FIRST_COMMIT_SHA }}
fi
COMMIT_RANGE="${{ env.BASE_SHA }}..origin/${{ env.HEAD_BRANCH }}"
echo "Commit range: ${COMMIT_RANGE}"
echo "Commit range: $COMMIT_RANGE"
NON_MERGE_COMMITS=$(git log ${COMMIT_RANGE} --reverse --no-merges --pretty=format:"%h" -- | xargs)
echo "Ordered non-merge commits: $NON_MERGE_COMMITS"
# Attempt to cherry-pick the commits from the original PR
CHERRY_PICK_OUTPUT=$(git cherry-pick $COMMIT_RANGE 2>&1) || {
CHERRY_PICK_OUTPUT=$(git cherry-pick ${NON_MERGE_COMMITS} 2>&1) || {
git cherry-pick --abort || true
# If cherry-pick fails, create a placeholder commit
echo "Cherry-pick failed. Creating placeholder commit."
GIT_LOG_ONELINE_OUTPUT=$(git log --oneline --no-decorate $COMMIT_RANGE)
git reset --hard
git commit --allow-empty -m "Placeholder commit for PR #${{ env.PR_ID }}"
Expand All @@ -154,17 +219,21 @@ jobs:
git checkout $NEW_BRANCH
git reset --hard HEAD~1 # Remove placeholder commit
git cherry-pick $COMMIT_RANGE
git cherry-pick $NON_MERGE_COMMITS
\`\`\`
**Individual commits:**
\`\`\`
$GIT_LOG_ONELINE_OUTPUT
\`\`\`
"
}
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
echo "This is a dry run."
echo "Would have pushed the new branch $NEW_BRANCH"
echo "PR title: $SEMANTIC_PR_TITLE"
echo "PR body:"
echo "$PR_BODY"
exit 0
fi
# Push the new branch
git push origin $NEW_BRANCH
Expand All @@ -178,6 +247,4 @@ jobs:
AUTHOR=${{ env.PR_MERGER }}
fi
fi
gh pr create --title "$SEMANTIC_PR_TITLE" --body "$PR_BODY" --head "$NEW_BRANCH" --base "${{ env.RELEASE_BRANCH }}" --assignee "$AUTHOR" --reviewer "$AUTHOR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
gh pr create --title "$SEMANTIC_PR_TITLE" --body "$PR_BODY" --head "$NEW_BRANCH" --base "$RELEASE_BRANCH" --assignee "$AUTHOR" --reviewer "$AUTHOR"
19 changes: 19 additions & 0 deletions .github/workflows/check-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Verify CHANGELOG.md is updated

on: [pull_request]

jobs:
check:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: mskelton/changelog-reminder-action@v3
with:
message: >
Oops! Looks like you forgot to update the changelog.
When updating CHANGELOG.md, please consider the following:
- Changelog is read by country implementors who might not always be familiar with all technical details of OpenCRVS. Keep language high-level, user friendly and avoid technical references to internals.
- Answer "What's new?", "Why was the change made?" and "Why should I care?" for each change.
- If it's a breaking change, include a migration guide answering "What do I need to do to upgrade?".
6 changes: 3 additions & 3 deletions .github/workflows/clear-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
name: 'Reset data'
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
timeout-minutes: 60
outputs:
outcome: ${{ steps.reset.outcome }}
outcome: ${{ steps.reset-data.outcome }}
timeout-minutes: 60
steps:
- name: Clone country config resource package
uses: actions/checkout@v3
Expand All @@ -50,7 +50,7 @@ jobs:
known_hosts: ${{ env.KNOWN_HOSTS }}

- name: Reset data
id: reset
id: reset-data
env:
HOST: ${{ vars.DOMAIN }}
ENV: ${{ vars.ENVIRONMENT_TYPE }}
Expand Down
19 changes: 6 additions & 13 deletions .github/workflows/deploy-and-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
echo "test_matrix=$test_dirs"
test:
needs: [deploy, discover-tests]
needs: [deploy, discover-tests, get-core-commit, get-country-config-commit]
runs-on: ubuntu-22.04
environment: ${{ github.event.inputs.environment || 'development' }}
strategy:
Expand Down Expand Up @@ -136,9 +136,9 @@ jobs:
DOMAIN: '${{ vars.DOMAIN }}'

- uses: actions/upload-artifact@v4
if: steps.check-specs.outputs.has_spec_files == 'true'
if: always() && steps.check-specs.outputs.has_spec_files == 'true'
with:
name: playwright-report-${{ matrix.test_dir }}
name: playwright-report-${{github.event.inputs.core-image-tag || needs.get-core-commit.outputs.latest_commit_sha}}-${{github.event.inputs.countryconfig-image-tag || needs.get-country-config-commit.outputs.short_sha}}-${{matrix.test_dir}}
path: playwright-report/
retention-days: 30

Expand All @@ -150,19 +150,13 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get Previous Workflow Run
id: get-previous-run
run: |
previous_run_id=$(gh run list --limit 2 --json databaseId -q '.[1].databaseId')
echo "PREVIOUS_RUN_ID=$previous_run_id" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
with:
fetch-depth: 0

- name: Get Previous Run Conclusion
id: get-previous-conclusion
run: |
previous_conclusion=$(gh run view $PREVIOUS_RUN_ID --json conclusion -q '.conclusion')
previous_conclusion=$(gh run list --limit 1 --status=completed --workflow="Deploy & run E2E" --json conclusion -q '.[0].conclusion')
echo "PREVIOUS_CONCLUSION=$previous_conclusion" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
Expand All @@ -179,7 +173,6 @@ jobs:
if: failure()
steps:
- name: Send Slack notification
if: needs.get-previous-run.outputs.previous_run_result == 'success'
uses: slackapi/[email protected]
with:
channel-id: 'C02LU432JGK'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: trstringer/manual-approval@v1
with:
secret: ${{ github.TOKEN }}
approvers: euanmillar,rikukissa
approvers: euanmillar,rikukissa,alsmk
minimum-approvals: 1
issue-title: 'Deploy (${{ github.event.inputs.environment }}): core: ${{ github.event.inputs.core-image-tag }} country config: ${{ github.event.inputs.countryconfig-image-tag }}'
issue-body: 'Please approve or deny the deployment of core: ${{ github.event.inputs.core-image-tag }} country config: ${{ github.event.inputs.countryconfig-image-tag }} to ${{ github.event.inputs.environment }}'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
run: npx playwright test ./e2e/testcases/${{ matrix.test_dir }}
env:
DOMAIN: '${{ vars.DOMAIN }}'
continue-on-error: true

- uses: actions/upload-artifact@v4
if: steps.check-specs.outputs.has_spec_files == 'true'
Expand Down
Loading

0 comments on commit ca92386

Please sign in to comment.