forked from opencrvs/opencrvs-countryconfig
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
232 changed files
with
30,546 additions
and
13,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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' }} | ||
|
@@ -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 }}" | ||
|
@@ -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 | ||
|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
||
|
@@ -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 }} | ||
|
@@ -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' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.