Skip to content

Commit

Permalink
ci: split rc e2e release into 2 workflows and migrate some of the cod…
Browse files Browse the repository at this point in the history
…e to nodejs
  • Loading branch information
necipallef committed Oct 3, 2024
1 parent fe0fc54 commit fe530a1
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e_test_for_prs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: AWS E2E for topic branch
name: Run AWS E2E for topic branch

on:
pull_request:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/e2e_test_for_release_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Check AWS E2E for releases and pre-releases

on:
pull_request:
branches:
- main

jobs:
check-commit-with-tag-and-old-tests:
runs-on: ubuntu-20.04
name: Check latest commit with tag and its checks
steps:
- name: 'Install latest node version'
uses: actions/setup-node@v4

- name: Git clone
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check latest commit with tag
id: latest_commit_with_test
run: |
diff=$(git log origin/$GITHUB_BASE_REF..HEAD --oneline --format="%H")
echo "diff=$diff"
latestCommitWithTag=''
for commit in $diff; do
echo "checking commit $commit for tag"
tag=$(git tag --points-at "$commit")
if [[ -n "$tag" ]]; then
latestCommitWithTag=$commit
break
fi
done
echo "latestCommitWithTag=$latestCommitWithTag"
echo "latestCommitWithTag=$latestCommitWithTag" >> $GITHUB_OUTPUT
if [[ -z "$latestCommitWithTag" ]]; then
echo "no tag has found. Skipping..."
fi
- name: Poll checks from GitHub
if: steps.latest_commit_with_test.outputs.latestCommitWithTag != ''
run: node scripts/checkCommitStatusForE2E.mjs
env:
COMMIT_SHA: ${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
GITHUB_REPOSITORY: ${{ github.repository }}
111 changes: 10 additions & 101 deletions .github/workflows/e2e_test_for_releases.yml
Original file line number Diff line number Diff line change
@@ -1,109 +1,13 @@
name: AWS E2E for releases and pre-releases
name: Run AWS E2E for releases and pre-releases

on:
workflow_dispatch:
pull_request:
branches:
- main
push:
tags:
- v*

jobs:
check-commit-with-tag-and-old-tests:
runs-on: ubuntu-20.04
name: Check latest commit with tag and its checks
outputs:
NEED_TO_RUN_TESTS: ${{ steps.decision.outputs.NEED_TO_RUN_TESTS }}
COMMIT_WITH_TAG: ${{ steps.decision.outputs.COMMIT_WITH_TAG }}
steps:
- name: Git clone
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check latest commit with tag
id: latest_commit_with_test
run: |
diff=$(git log origin/$GITHUB_BASE_REF..HEAD --oneline --format="%H")
echo "diff=$diff"
latestCommitWithTag=''
for commit in $diff; do
echo "checking commit $commit for tag"
tag=$(git tag --points-at "$commit")
if [[ -n "$tag" ]]; then
latestCommitWithTag=$commit
break
fi
done
echo "latestCommitWithTag=$latestCommitWithTag"
echo "latestCommitWithTag=$latestCommitWithTag" >> $GITHUB_OUTPUT
- name: Fetch checks from GitHub
id: response_from_github
if: steps.latest_commit_with_test.outputs.latestCommitWithTag != ''
run: |
latestCommitWithTag=${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
api_url="repos/$GITHUB_REPOSITORY/commits/$latestCommitWithTag/check-runs"
full_url="https://api.github.com/$api_url"
echo "full_url=$full_url"
response=$(curl \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
$full_url)
if [[ $? -ne 0 ]]; then
echo "Failed to fetch check runs. Exiting."
exit 1
fi
if ! echo "$response" | jq . >/dev/null 2>&1; then
echo "Invalid JSON response: $response"
exit 1
fi
file_name=response_from_github.json
echo "$response" > $file_name
echo "filename=$file_name" >> $GITHUB_OUTPUT
- name: Find test conclusion
if: steps.response_from_github.outputs.filename != ''
id: conclusion
run: |
latestCommitWithTag=${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
response="$(cat ${{ steps.response_from_github.outputs.filename }} )"
needToRunTests=false
number_of_checks=$(echo "$response" | jq '.check_runs | length')
echo "# of check runs=$number_of_checks"
run_conclusion='(empty)'
if [[ "$number_of_checks" -ne 0 ]]; then
# Note: Iterating with `for run in $(...)` can lead issues with whitespaces, so using `while read` here
while read -r run; do
run_name=$(echo "$run" | jq -r '.name')
echo "run_name=$run_name"
if [[ "$run_name" == 'Run e2e for releases and pre-releases' ]]; then
run_conclusion=$(echo "$run" | jq -r '.conclusion')
break
fi
done < <(echo "$response" | jq -c '.check_runs[]')
fi
echo "run_conclusion=$run_conclusion"
echo "run_conclusion=$run_conclusion" >> $GITHUB_OUTPUT
- name: Decide whether to run tests
id: decision
run: |
latestCommitWithTag=${{ steps.latest_commit_with_test.outputs.latestCommitWithTag }}
run_conclusion=${{ steps.conclusion.outputs.run_conclusion }}
if [[ -z "$latestCommitWithTag" ]]; then
echo "no tag has found. Skipping..."
elif [[ "$run_conclusion" == "success" ]]; then
echo "test has run successfully before. Skipping..."
elif [[ "$run_conclusion" == "failure" ]]; then
echo "test has failed before. Exiting..."
exit 1
else
echo "test has not run before. Continuing..."
echo "COMMIT_WITH_TAG=${latestCommitWithTag}" >> $GITHUB_OUTPUT
echo "NEED_TO_RUN_TESTS=true" >> $GITHUB_OUTPUT
fi
run-e2e-for-releases-and-pre-releases:
needs: check-commit-with-tag-and-old-tests
if: needs['check-commit-with-tag-and-old-tests'].outputs.NEED_TO_RUN_TESTS == 'true'
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
Expand All @@ -112,14 +16,19 @@ jobs:
steps:
- name: Git clone
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 #v4.0.2
with:
role-to-assume: ${{secrets.AWS_E2E_ROLE_ARN}}
aws-region: ${{vars.AWS_E2E_REGION}}
- name: Trigger AWS CodePipeline
run: |
codepipeline_execution_id=$(aws codepipeline start-pipeline-execution --name ${{vars.AWS_E2E_RC_CODEPIPELINE_NAME}} --source-revisions actionName=Source,revisionType=COMMIT_ID,revisionValue=${{needs['check-commit-with-tag-and-old-tests'].outputs.COMMIT_WITH_TAG}} --query 'pipelineExecutionId' --output text)
commit=${{ github.sha }}
tag=$(git tag --points-at "$commit")
echo "Running tests for tag: $tag and commit SHA: $commit"
codepipeline_execution_id=$(aws codepipeline start-pipeline-execution --name ${{vars.AWS_E2E_RC_CODEPIPELINE_NAME}} --source-revisions actionName=Source,revisionType=COMMIT_ID,revisionValue=$commit --query 'pipelineExecutionId' --output text)
echo "Pipeline execution ID: $codepipeline_execution_id"
echo "codepipeline_execution_id=$codepipeline_execution_id" >> $GITHUB_ENV
- name: Poll Pipeline Status
Expand Down
66 changes: 66 additions & 0 deletions scripts/checkCommitStatusForE2E.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const commitSHA = process.env.COMMIT_SHA
const gitHubRepo = process.env.GITHUB_REPOSITORY

const apiURL = `repos/${gitHubRepo}/commits/${commitSHA}/check-runs`
const fullURL = `https://api.github.com/${apiURL}`

const E2E_TEST_NAME = "Run e2e for releases and pre-releases"
const POLL_WAIT_DURATION = 30_000

function checkEnv() {
if (!commitSHA) {
throw new Error("env var COMMIT_SHA not found.")
}

console.log(`COMMIT_SHA=${commitSHA}`)

if (!gitHubRepo) {
throw new Error("env var GITHUB_REPOSITORY not found.")
}

console.log(`GITHUB_REPOSITORY=${gitHubRepo}`)
}

async function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

async function findCheckRun() {
const response = await fetch(fullURL)
if (!response.ok) {
throw new Error(`request to GitHub failed with HTTP ${response.status}.`)
}

const responseBody = await response.json()
console.log(`# of check runs: ${responseBody.check_runs.length}`)
return responseBody.check_runs.find(r => r.name === E2E_TEST_NAME)
}

async function main() {
checkEnv()

while (true) {
const checkRun = await findCheckRun()
if (checkRun) {
const conclusion = checkRun.conclusion
console.log(`conclusion=${conclusion}`)
if (conclusion === "success") {
break
}

if (conclusion === "failure") {
throw new Error("e2e test has failed. Exiting")
}
}

await wait(POLL_WAIT_DURATION)
}

console.log("e2e test has passed! Exiting")
}


main().catch((err) => {
console.error(err)
process.exit(1)
})

0 comments on commit fe530a1

Please sign in to comment.