From 356e5e8400ff0a8e5f3880f7454dfa7096a36549 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 11:52:11 +0200 Subject: [PATCH 01/45] gi-flow --- .github/workflows/accept-baseline.yml | 97 ++++++++++++++++---- .github/workflows/run-tests.yml | 24 +++-- .github/workflows/start-accept-baselines.yml | 27 ------ 3 files changed, 90 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/start-accept-baselines.yml diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index e4103017..d9142eec 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -1,36 +1,97 @@ -name: Accept Ghost Inspector Snapshots New Baseline on Merge +name: Accept Baselines Workflow on: - workflow_run: - workflows: ["Accept New Baseline"] + pull_request: types: - - completed + - labeled + +permissions: + contents: write jobs: - accept-baseline: + check-conditions: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Download Baseline Acceptance Artifact - uses: actions/download-artifact@v3 - with: - name: baseline-acceptance - - name: Validate Baseline Acceptance + - name: Validate Conditions + run: | + if [[ "${{ github.event.pull_request.merged }}" == "true" ]]; then + echo "PR is already merged. Exiting." + exit 1 + fi + + if [[ ! "${{ github.event.label.name }}" == "accept-baselines" ]]; then + echo "Label 'accept-baselines' not found. Exiting." + exit 1 + fi + - name: Verify Required Checks run: | - if [ ! -f accept_baseline_flag ]; then - echo "Baseline acceptance flag not found." + CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json checks --jq '.checks[].status') + if [[ "$CHECKS" =~ "failure" ]]; then + echo "Some required checks failed. Exiting." exit 1 fi - - name: Update Baseline in Ghost Inspector + + - name: Verify Approvals + run: | + APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') + if [[ "$APPROVALS" -lt 2 ]]; then + echo "Not enough approvals. Exiting." + exit 1 + fi + + acquire-lock: + needs: check-conditions + runs-on: ubuntu-latest + steps: + - name: Check for Lock + id: check-lock + run: | + LOCK_FILE_URL="https://raw.githubusercontent.com///main/.baseline-lock" + STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" $LOCK_FILE_URL) + if [ "$STATUS_CODE" == "200" ]; then + echo "Baseline update is already in progress. Exiting." + exit 1 + fi + - name: Acquire Lock + run: | + echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock + git config user.name "github-actions" + git config user.email "actions@github.com" + git checkout main + git pull origin main + git add .baseline-lock + git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" + git push origin main + + update-baselines: + needs: acquire-lock + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Update Baselines in Ghost Inspector run: npm run test:accept-baseline env: GI_KEY: ${{ secrets.GI_KEY }} - ACCEPT_NEW_BASELINE: 'true' - - name: Mark PR as Safe to Merge - run: echo "The baseline has been updated successfully. The PR is safe to merge." + + - name: Release Lock + if: success() + run: | + git config user.name "github-actions" + git config user.email "actions@github.com" + git checkout main + git pull origin main + git rm .baseline-lock + git commit -m "Release lock for baseline update" + git push origin main + + auto-merge: + needs: update-baselines + runs-on: ubuntu-latest + steps: - name: Auto-Merge PR if: success() run: gh pr merge ${{ github.event.pull_request.number }} --squash --admin env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 69dd07e6..c61e92d4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,8 +1,12 @@ -name: Lint, unit tests, and snapshots +name: Run Tests and Snapshots on: pull_request: types: [opened, synchronize, reopened] + workflow_run: + workflows: ["Accept Baselines Workflow"] + types: + - completed jobs: setup-nodejs: @@ -32,7 +36,7 @@ jobs: - run: npm run test:unit snapshots-tests: - needs: setup-nodejs + needs: [lint, unit-tests] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -41,15 +45,9 @@ jobs: run: npm run test:snapshots env: GI_KEY: ${{ secrets.GI_KEY }} - - name: Inform Developer About Failing Snapshots - if: failure() # This runs if snapshot tests fail - run: echo "Snapshots failed. Check your code or accept new baselines in the GitHub Actions tab." - - name: Save Accept Baseline Option - if: failure() - run: echo "baseline_failure=true" > baseline_failure_flag - - name: Upload Baseline Acceptance Artifact + - name: Inform Developer About Snapshot Failures if: failure() - uses: actions/upload-artifact@v3 - with: - name: baseline-acceptance - path: baseline_failure_flag + run: echo "Snapshots failed. Add the 'accept-baselines' label to update the baselines or fix your code." + - name: Set PR Ready for Merge + if: success() + run: echo "PR is ready for merge." diff --git a/.github/workflows/start-accept-baselines.yml b/.github/workflows/start-accept-baselines.yml deleted file mode 100644 index a0e8c6cc..00000000 --- a/.github/workflows/start-accept-baselines.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Accept New Baselines - -on: - workflow_dispatch: - inputs: - confirm_baseline: - description: 'Type "yes" to accept the new baseline' - required: true - default: '' - -jobs: - accept-baseline-trigger: - runs-on: ubuntu-latest - steps: - - name: Validate Input - run: | - if [ "${{ github.event.inputs.confirm_baseline }}" != "yes" ]; then - echo "You must type 'yes' to accept the baseline." - exit 1 - fi - - name: Set Baseline Acceptance Flag - run: echo "baseline_accepted=true" > accept_baseline_flag - - name: Upload Baseline Acceptance Flag - uses: actions/upload-artifact@v3 - with: - name: baseline-acceptance - path: accept_baseline_flag From b1c1c0ff8a1638efae697f315e5a52254c18e79a Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 11:57:24 +0200 Subject: [PATCH 02/45] gi-flow --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index d9142eec..64b58901 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -46,7 +46,7 @@ jobs: - name: Check for Lock id: check-lock run: | - LOCK_FILE_URL="https://raw.githubusercontent.com///main/.baseline-lock" + LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/main/.baseline-lock" STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" $LOCK_FILE_URL) if [ "$STATUS_CODE" == "200" ]; then echo "Baseline update is already in progress. Exiting." From c5fd97a30a244d62ece18191834feccc65ada6d2 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 12:03:36 +0200 Subject: [PATCH 03/45] gi-flow --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 64b58901..443d5ac7 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -46,7 +46,7 @@ jobs: - name: Check for Lock id: check-lock run: | - LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/main/.baseline-lock" + LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/gi-flow/.baseline-lock" STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" $LOCK_FILE_URL) if [ "$STATUS_CODE" == "200" ]; then echo "Baseline update is already in progress. Exiting." From 72c13c1fad286d7e19384338496d14e51bdab420 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 12:53:30 +0200 Subject: [PATCH 04/45] gi-flow --- .github/workflows/accept-baseline.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 443d5ac7..194e125a 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -30,6 +30,8 @@ jobs: echo "Some required checks failed. Exiting." exit 1 fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Verify Approvals run: | @@ -38,6 +40,8 @@ jobs: echo "Not enough approvals. Exiting." exit 1 fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} acquire-lock: needs: check-conditions @@ -52,6 +56,9 @@ jobs: echo "Baseline update is already in progress. Exiting." exit 1 fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Acquire Lock run: | echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock @@ -62,6 +69,8 @@ jobs: git add .baseline-lock git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" git push origin main + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} update-baselines: needs: acquire-lock @@ -85,6 +94,8 @@ jobs: git rm .baseline-lock git commit -m "Release lock for baseline update" git push origin main + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} auto-merge: needs: update-baselines From 8381aed47c5b5abd44790f189afe68d96a8db383 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 13:17:51 +0200 Subject: [PATCH 05/45] gi-flow --- .github/workflows/accept-baseline.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 194e125a..a01547e1 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -25,10 +25,12 @@ jobs: fi - name: Verify Required Checks run: | - CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json checks --jq '.checks[].status') - if [[ "$CHECKS" =~ "failure" ]]; then - echo "Some required checks failed. Exiting." + CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS") | .name') + if [ -n "$CHECKS" ]; then + echo "Some required checks failed: $CHECKS" exit 1 + else + echo "All required checks passed." fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 48c51afcc1616c3fedb466745f501a600ea11239 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 13:21:03 +0200 Subject: [PATCH 06/45] Update workflow files [skip ci] --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index a01547e1..3d6f37cd 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -30,7 +30,7 @@ jobs: echo "Some required checks failed: $CHECKS" exit 1 else - echo "All required checks passed." + echo "All required checks passed.." fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From edd55ba510d023defcaaebd0ebc3f596b810d676 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 13:26:30 +0200 Subject: [PATCH 07/45] gi-flow --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 3d6f37cd..a01547e1 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -30,7 +30,7 @@ jobs: echo "Some required checks failed: $CHECKS" exit 1 else - echo "All required checks passed.." + echo "All required checks passed." fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From fb1007c6930afeefa45f89ba433f51c8533ccc2d Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 13:34:14 +0200 Subject: [PATCH 08/45] gi-flow --- .github/workflows/accept-baseline.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index a01547e1..374ef4c8 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -23,6 +23,8 @@ jobs: echo "Label 'accept-baselines' not found. Exiting." exit 1 fi + - name: Checkout Repository + uses: actions/checkout@v3 - name: Verify Required Checks run: | CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS") | .name') From 5c10e7b6e626dce3fc3d63a29c61446638bcfde0 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 14:01:50 +0200 Subject: [PATCH 09/45] gi-flow --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 374ef4c8..8b998472 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v3 - name: Verify Required Checks run: | - CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS") | .name') + CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests") | .name') if [ -n "$CHECKS" ]; then echo "Some required checks failed: $CHECKS" exit 1 From d46b99857aeb3d2643f12de4a61334e0ef1bcbf4 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 14:12:02 +0200 Subject: [PATCH 10/45] temporary skip check for aem-psi-check --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 8b998472..e6dc29dc 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v3 - name: Verify Required Checks run: | - CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests") | .name') + CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests" and .name != "aem-psi-check") | .name') if [ -n "$CHECKS" ]; then echo "Some required checks failed: $CHECKS" exit 1 From c63bfd4ad13401bcbb55732b630066a37765f37e Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 14:21:52 +0200 Subject: [PATCH 11/45] temporary mock snapshot testing --- .github/workflows/accept-baseline.yml | 2 +- ghosti/index.js | 141 +++++++++++++------------- 2 files changed, 73 insertions(+), 70 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index e6dc29dc..e6268c7a 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v3 - name: Verify Required Checks run: | - CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests" and .name != "aem-psi-check") | .name') + CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests" and .name != "check-conditions" and .name != "aem-psi-check") | .name') if [ -n "$CHECKS" ]; then echo "Some required checks failed: $CHECKS" exit 1 diff --git a/ghosti/index.js b/ghosti/index.js index 8aa9d217..756868dd 100644 --- a/ghosti/index.js +++ b/ghosti/index.js @@ -74,73 +74,76 @@ const EXCLUDED_SNAPSHOT_BLOCKS = [ } } - try { - const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - // get snapshots tests - const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); - - const snapshotsPromises = blockSnapshotsToTest - .map((testName) => { - const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); - - if (testAlreadyExists) { - return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`).then((res) => res.json()); - } - - return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ - name: testName, - startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, - }).generate()) - .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); - }); - - const [ - snapshotsResult, - ] = await Promise.all([ - Promise.all(snapshotsPromises), - ]); - - showSnapshotTestsFullLogs(snapshotsResult); - } catch (err) { - console.error(err); - process.exit(1); - } - - try { - const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - - // get snapshots tests - const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); - - const batches = createBatches(blockSnapshotsToTest, 3); - - let allTestResults = []; - - for (const batch of batches) { - const snapshotsPromises = batch.map((testName) => { - const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); - if (testAlreadyExists) { - return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { - signal: AbortSignal.timeout(FETCH_TIMEOUT) - }).then((res) => res.json()); - } - console.log('New test was imported', testName); - return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ - name: testName, - startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, - }).generate()) - .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); - }); - - // Await the completion of all promises in the current batch before proceeding to the next - const batchResults = await Promise.all(snapshotsPromises); - allTestResults.push(...batchResults); - } - - // Once all batches are processed, show the full logs of the snapshot tests - showSnapshotTestsFullLogs(allTestResults); - } catch (err) { - console.error(err); - process.exit(1); - } + // todo mock test + // try { + // const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); + // // get snapshots tests + // const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); + // + // const snapshotsPromises = blockSnapshotsToTest + // .map((testName) => { + // const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + // + // if (testAlreadyExists) { + // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`).then((res) => res.json()); + // } + // + // return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ + // name: testName, + // startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, + // }).generate()) + // .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); + // }); + // + // const [ + // snapshotsResult, + // ] = await Promise.all([ + // Promise.all(snapshotsPromises), + // ]); + // + // showSnapshotTestsFullLogs(snapshotsResult); + // } catch (err) { + // console.error(err); + // process.exit(1); + // } + // + // try { + // const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); + // + // // get snapshots tests + // const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); + // + // const batches = createBatches(blockSnapshotsToTest, 3); + // + // let allTestResults = []; + // + // for (const batch of batches) { + // const snapshotsPromises = batch.map((testName) => { + // const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + // if (testAlreadyExists) { + // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { + // signal: AbortSignal.timeout(FETCH_TIMEOUT) + // }).then((res) => res.json()); + // } + // console.log('New test was imported', testName); + // return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ + // name: testName, + // startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, + // }).generate()) + // .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); + // }); + // + // // Await the completion of all promises in the current batch before proceeding to the next + // const batchResults = await Promise.all(snapshotsPromises); + // allTestResults.push(...batchResults); + // } + // + // // Once all batches are processed, show the full logs of the snapshot tests + // showSnapshotTestsFullLogs(allTestResults); + // } catch (err) { + // console.error(err); + // process.exit(1); + // } + + await new Promise((res) => setTimeout(res, 1000)) })(); From 422d44288e466ae59df85e69c9b6591c65ec5e45 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 14:33:33 +0200 Subject: [PATCH 12/45] Acquire Lock - fix --- .github/workflows/accept-baseline.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index e6268c7a..eecb9309 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -51,6 +51,9 @@ jobs: needs: check-conditions runs-on: ubuntu-latest steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Check for Lock id: check-lock run: | From 6632f78a11166a2327c251d7bf0c766c7f36dc15 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 14:36:22 +0200 Subject: [PATCH 13/45] Verify Approvals - temp remove --- .github/workflows/accept-baseline.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index eecb9309..9dd043b9 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -37,15 +37,15 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Verify Approvals - run: | - APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') - if [[ "$APPROVALS" -lt 2 ]]; then - echo "Not enough approvals. Exiting." - exit 1 - fi - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# - name: Verify Approvals +# run: | +# APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') +# if [[ "$APPROVALS" -lt 2 ]]; then +# echo "Not enough approvals. Exiting." +# exit 1 +# fi +# env: +# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} acquire-lock: needs: check-conditions From 52ab4e605e5d21da9dacb3e6fb11aa69bd9499e0 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 14:53:50 +0200 Subject: [PATCH 14/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 9dd043b9..cba09f82 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -71,11 +71,11 @@ jobs: echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock git config user.name "github-actions" git config user.email "actions@github.com" - git checkout main - git pull origin main + git checkout gi-flow + git pull origin gi-flow git add .baseline-lock git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" - git push origin main + git push origin gi-flow env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 525409d3510602c6f01a27323ff49807b60ebfd6 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 15:00:46 +0200 Subject: [PATCH 15/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index cba09f82..26091960 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -71,6 +71,7 @@ jobs: echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock git config user.name "github-actions" git config user.email "actions@github.com" + git fetch origin gi-flow:gi-flow git checkout gi-flow git pull origin gi-flow git add .baseline-lock From a9ded68639346977dc69e06d97cdc0566b987fc8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 13:05:34 +0000 Subject: [PATCH 16/45] Lock for baseline update by PR #430 --- .baseline-lock | 1 + 1 file changed, 1 insertion(+) create mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock new file mode 100644 index 00000000..757267ad --- /dev/null +++ b/.baseline-lock @@ -0,0 +1 @@ +Updating baselines for PR #430 From 10de4de9a914a322e1935252657f8e13a3329c95 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 15:13:59 +0200 Subject: [PATCH 17/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 26091960..bbbccaa1 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -87,6 +87,12 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.4' + - run: npm install + - name: Update Baselines in Ghost Inspector run: npm run test:accept-baseline env: From 4ec368c103bf0b07fbec0b4e18d5ba062a210860 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 15:29:33 +0200 Subject: [PATCH 18/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index bbbccaa1..81d18fa2 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -93,6 +93,20 @@ jobs: node-version: '20.4' - run: npm install + - name: Create Lock File + run: | + echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock + git config user.name "github-actions" + git config user.email "actions@github.com" + git fetch origin gi-flow:gi-flow + git checkout gi-flow + git pull origin gi-flow + git add .baseline-lock + git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" + git push origin gi-flow + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Update Baselines in Ghost Inspector run: npm run test:accept-baseline env: @@ -103,11 +117,12 @@ jobs: run: | git config user.name "github-actions" git config user.email "actions@github.com" - git checkout main - git pull origin main + git fetch origin gi-flow:gi-flow + git checkout gi-flow + git pull origin gi-flow git rm .baseline-lock git commit -m "Release lock for baseline update" - git push origin main + git push origin gi-flow env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d38aeb7efa7894fc55611aab72a3e37b011c2051 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 15:30:17 +0200 Subject: [PATCH 19/45] Acquire Lock - temp change to local branch --- .baseline-lock | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock deleted file mode 100644 index 757267ad..00000000 --- a/.baseline-lock +++ /dev/null @@ -1 +0,0 @@ -Updating baselines for PR #430 From 2fa8e605f4b1d06471d2bbcd117e37f620dd3bf8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 13:32:25 +0000 Subject: [PATCH 20/45] Lock for baseline update by PR #430 --- .baseline-lock | 1 + 1 file changed, 1 insertion(+) create mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock new file mode 100644 index 00000000..757267ad --- /dev/null +++ b/.baseline-lock @@ -0,0 +1 @@ +Updating baselines for PR #430 From 168766006c70e44e2b740d99222ad186a9a9de68 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 15:44:44 +0200 Subject: [PATCH 21/45] Acquire Lock - temp change to local branch --- .baseline-lock | 1 - .github/workflows/accept-baseline.yml | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock deleted file mode 100644 index 757267ad..00000000 --- a/.baseline-lock +++ /dev/null @@ -1 +0,0 @@ -Updating baselines for PR #430 diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 81d18fa2..36b6ee51 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -84,8 +84,10 @@ jobs: needs: acquire-lock runs-on: ubuntu-latest steps: - - name: Checkout Code + - name: Checkout `gi-flow` Branch uses: actions/checkout@v3 + with: + ref: gi-flow - name: Use Node.js uses: actions/setup-node@v3 @@ -98,8 +100,6 @@ jobs: echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock git config user.name "github-actions" git config user.email "actions@github.com" - git fetch origin gi-flow:gi-flow - git checkout gi-flow git pull origin gi-flow git add .baseline-lock git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" @@ -117,8 +117,6 @@ jobs: run: | git config user.name "github-actions" git config user.email "actions@github.com" - git fetch origin gi-flow:gi-flow - git checkout gi-flow git pull origin gi-flow git rm .baseline-lock git commit -m "Release lock for baseline update" From e7c5a08e35302b8949545bb65dbf9c2e407ce279 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 13:48:12 +0000 Subject: [PATCH 22/45] Lock for baseline update by PR #430 --- .baseline-lock | 1 + 1 file changed, 1 insertion(+) create mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock new file mode 100644 index 00000000..757267ad --- /dev/null +++ b/.baseline-lock @@ -0,0 +1 @@ +Updating baselines for PR #430 From abe003ecb003b5cc92f82e9616a0ed750cc535b3 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:00:04 +0200 Subject: [PATCH 23/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 4 ++-- .husky/pre-commit | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 36b6ee51..ebb4715d 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -102,7 +102,7 @@ jobs: git config user.email "actions@github.com" git pull origin gi-flow git add .baseline-lock - git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" + git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }} [skip husky]" git push origin gi-flow env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -119,7 +119,7 @@ jobs: git config user.email "actions@github.com" git pull origin gi-flow git rm .baseline-lock - git commit -m "Release lock for baseline update" + git commit -m "Release lock for baseline update [skip husky]" git push origin gi-flow env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.husky/pre-commit b/.husky/pre-commit index 537dac9e..ecc3602b 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,9 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +if git log -1 --pretty=%B | grep -q "\[skip husky\]"; then + echo "Skipping Husky hooks for this commit." + exit 0 +fi + npm run lint && npm run test:unit From 88f07702157f7bfcc4ddeaaf9a60a9687e7d02ae Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:00:27 +0200 Subject: [PATCH 24/45] Acquire Lock - temp change to local branch --- .baseline-lock | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock deleted file mode 100644 index 757267ad..00000000 --- a/.baseline-lock +++ /dev/null @@ -1 +0,0 @@ -Updating baselines for PR #430 From e4f8cf9913cf2342377854f61180b7abc2ac1adb Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:02:37 +0000 Subject: [PATCH 25/45] Lock for baseline update by PR #430 --- .baseline-lock | 1 + 1 file changed, 1 insertion(+) create mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock new file mode 100644 index 00000000..757267ad --- /dev/null +++ b/.baseline-lock @@ -0,0 +1 @@ +Updating baselines for PR #430 From a6d16ea70eb74bd11b9c446898a6e21ed5d00788 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:11:34 +0200 Subject: [PATCH 26/45] Acquire Lock - temp change to local branch --- .baseline-lock | 1 - .github/workflows/accept-baseline.yml | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) delete mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock deleted file mode 100644 index 757267ad..00000000 --- a/.baseline-lock +++ /dev/null @@ -1 +0,0 @@ -Updating baselines for PR #430 diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index ebb4715d..44dbd450 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -101,9 +101,19 @@ jobs: git config user.name "github-actions" git config user.email "actions@github.com" git pull origin gi-flow + + # Update the lock file with unique content + echo "$(date +%s): Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock + git add .baseline-lock - git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }} [skip husky]" - git push origin gi-flow + + # Commit only if there are changes + if git diff --cached --quiet; then + echo "No changes to commit. Skipping commit." + else + git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }} [skip husky]" + git push origin gi-flow + fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 6c4c163d2adac4e0c859eab5b91d30c06ff06b95 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:16:20 +0000 Subject: [PATCH 27/45] Lock for baseline update by PR #430 --- .baseline-lock | 1 + 1 file changed, 1 insertion(+) create mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock new file mode 100644 index 00000000..757267ad --- /dev/null +++ b/.baseline-lock @@ -0,0 +1 @@ +Updating baselines for PR #430 From 031f500e0d755e6ff7811f161d0e92829cf94151 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:16:48 +0000 Subject: [PATCH 28/45] Lock for baseline update by PR #430 [skip husky] --- .baseline-lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.baseline-lock b/.baseline-lock index 757267ad..948d322e 100644 --- a/.baseline-lock +++ b/.baseline-lock @@ -1 +1 @@ -Updating baselines for PR #430 +1732025808: Updating baselines for PR #430 From b38ba8ca15e06abf94d4b3ba628076d4576b28e6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:17:00 +0000 Subject: [PATCH 29/45] Release lock for baseline update [skip husky] --- .baseline-lock | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock deleted file mode 100644 index 948d322e..00000000 --- a/.baseline-lock +++ /dev/null @@ -1 +0,0 @@ -1732025808: Updating baselines for PR #430 From ead8024e9e2ef6ac4d38679be754837fe139bd5d Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:23:46 +0200 Subject: [PATCH 30/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 44dbd450..a6a23bff 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -138,6 +138,9 @@ jobs: needs: update-baselines runs-on: ubuntu-latest steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Auto-Merge PR if: success() run: gh pr merge ${{ github.event.pull_request.number }} --squash --admin From 1326fb803f55b71d39d01c62759ab94db5eae465 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:27:04 +0000 Subject: [PATCH 31/45] Lock for baseline update by PR #430 --- .baseline-lock | 1 + 1 file changed, 1 insertion(+) create mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock new file mode 100644 index 00000000..757267ad --- /dev/null +++ b/.baseline-lock @@ -0,0 +1 @@ +Updating baselines for PR #430 From 095e7cc0568400d4d9a4f0f61af4670d4ea7e657 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:28:27 +0000 Subject: [PATCH 32/45] Lock for baseline update by PR #430 [skip husky] --- .baseline-lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.baseline-lock b/.baseline-lock index 757267ad..a88a0a40 100644 --- a/.baseline-lock +++ b/.baseline-lock @@ -1 +1 @@ -Updating baselines for PR #430 +1732026507: Updating baselines for PR #430 From 89d5dddd7caeb86da673306aa7c8097cb459e312 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Nov 2024 14:28:38 +0000 Subject: [PATCH 33/45] Release lock for baseline update [skip husky] --- .baseline-lock | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .baseline-lock diff --git a/.baseline-lock b/.baseline-lock deleted file mode 100644 index a88a0a40..00000000 --- a/.baseline-lock +++ /dev/null @@ -1 +0,0 @@ -1732026507: Updating baselines for PR #430 From 8359f4ee8625970b2529c6f840391eec9450af1c Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:37:49 +0200 Subject: [PATCH 34/45] Acquire Lock - temp change to local branch --- .github/workflows/accept-baseline.yml | 44 +++++++++++++++------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index a6a23bff..1c531f4a 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -37,15 +37,15 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# - name: Verify Approvals -# run: | -# APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') -# if [[ "$APPROVALS" -lt 2 ]]; then -# echo "Not enough approvals. Exiting." -# exit 1 -# fi -# env: -# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Verify Approvals + run: | + APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') + if [[ "$APPROVALS" -lt 2 ]]; then + echo "Not enough approvals. Exiting." + exit 1 + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} acquire-lock: needs: check-conditions @@ -53,11 +53,13 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v3 + with: + ref: main - name: Check for Lock id: check-lock run: | - LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/gi-flow/.baseline-lock" + LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/main/.baseline-lock" STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" $LOCK_FILE_URL) if [ "$STATUS_CODE" == "200" ]; then echo "Baseline update is already in progress. Exiting." @@ -69,14 +71,14 @@ jobs: - name: Acquire Lock run: | echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock + git config user.name "github-actions" git config user.email "actions@github.com" - git fetch origin gi-flow:gi-flow - git checkout gi-flow - git pull origin gi-flow + + git pull origin main git add .baseline-lock git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" - git push origin gi-flow + git push origin main env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -87,7 +89,7 @@ jobs: - name: Checkout `gi-flow` Branch uses: actions/checkout@v3 with: - ref: gi-flow + ref: main - name: Use Node.js uses: actions/setup-node@v3 @@ -98,9 +100,11 @@ jobs: - name: Create Lock File run: | echo "Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock + git config user.name "github-actions" git config user.email "actions@github.com" - git pull origin gi-flow + + git pull origin main # Update the lock file with unique content echo "$(date +%s): Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock @@ -112,7 +116,7 @@ jobs: echo "No changes to commit. Skipping commit." else git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }} [skip husky]" - git push origin gi-flow + git push origin main fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -127,10 +131,12 @@ jobs: run: | git config user.name "github-actions" git config user.email "actions@github.com" - git pull origin gi-flow + + git pull origin main + git rm .baseline-lock git commit -m "Release lock for baseline update [skip husky]" - git push origin gi-flow + git push origin main env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 001d221148510e8932f3e3d16d61a97b8d619bc3 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:40:37 +0200 Subject: [PATCH 35/45] Acquire Lock - temp change to local branch --- ghosti/index.js | 143 ++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/ghosti/index.js b/ghosti/index.js index 756868dd..5fa78d22 100644 --- a/ghosti/index.js +++ b/ghosti/index.js @@ -74,76 +74,75 @@ const EXCLUDED_SNAPSHOT_BLOCKS = [ } } - // todo mock test - // try { - // const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - // // get snapshots tests - // const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); - // - // const snapshotsPromises = blockSnapshotsToTest - // .map((testName) => { - // const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); - // - // if (testAlreadyExists) { - // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`).then((res) => res.json()); - // } - // - // return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ - // name: testName, - // startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, - // }).generate()) - // .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); - // }); - // - // const [ - // snapshotsResult, - // ] = await Promise.all([ - // Promise.all(snapshotsPromises), - // ]); - // - // showSnapshotTestsFullLogs(snapshotsResult); - // } catch (err) { - // console.error(err); - // process.exit(1); - // } - // - // try { - // const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - // - // // get snapshots tests - // const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); - // - // const batches = createBatches(blockSnapshotsToTest, 3); - // - // let allTestResults = []; - // - // for (const batch of batches) { - // const snapshotsPromises = batch.map((testName) => { - // const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); - // if (testAlreadyExists) { - // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { - // signal: AbortSignal.timeout(FETCH_TIMEOUT) - // }).then((res) => res.json()); - // } - // console.log('New test was imported', testName); - // return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ - // name: testName, - // startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, - // }).generate()) - // .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); - // }); - // - // // Await the completion of all promises in the current batch before proceeding to the next - // const batchResults = await Promise.all(snapshotsPromises); - // allTestResults.push(...batchResults); - // } - // - // // Once all batches are processed, show the full logs of the snapshot tests - // showSnapshotTestsFullLogs(allTestResults); - // } catch (err) { - // console.error(err); - // process.exit(1); - // } - - await new Promise((res) => setTimeout(res, 1000)) + try { + const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); + // get snapshots tests + const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); + + const snapshotsPromises = blockSnapshotsToTest + .map((testName) => { + const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + + if (testAlreadyExists) { + return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`).then((res) => res.json()); + } + + return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ + name: testName, + startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, + }).generate()) + .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); + }); + + const [ + snapshotsResult, + ] = await Promise.all([ + Promise.all(snapshotsPromises), + ]); + + showSnapshotTestsFullLogs(snapshotsResult); + } catch (err) { + console.error(err); + process.exit(1); + } + + try { + const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); + + // get snapshots tests + const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); + + const batches = createBatches(blockSnapshotsToTest, 3); + + let allTestResults = []; + + for (const batch of batches) { + const snapshotsPromises = batch.map((testName) => { + const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + if (testAlreadyExists) { + return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { + signal: AbortSignal.timeout(FETCH_TIMEOUT) + }).then((res) => res.json()); + } + console.log('New test was imported', testName); + return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ + name: testName, + startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, + }).generate()) + .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); + }); + + // Await the completion of all promises in the current batch before proceeding to the next + const batchResults = await Promise.all(snapshotsPromises); + allTestResults.push(...batchResults); + } + + // Once all batches are processed, show the full logs of the snapshot tests + showSnapshotTestsFullLogs(allTestResults); + } catch (err) { + console.error(err); + process.exit(1); + } + + // await new Promise((res) => setTimeout(res, 1000)) })(); From 479b76ad4cf7e3d0f45ec36825cbc77ddb18c42c Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 16:59:17 +0200 Subject: [PATCH 36/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 1c531f4a..f4810ee8 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -54,12 +54,12 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 with: - ref: main + ref: aquire-lock - name: Check for Lock id: check-lock run: | - LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/main/.baseline-lock" + LOCK_FILE_URL="https://github.com/bitdefender/www-landing-pages/blob/aquire-lock/.baseline-lock" STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" $LOCK_FILE_URL) if [ "$STATUS_CODE" == "200" ]; then echo "Baseline update is already in progress. Exiting." @@ -75,10 +75,10 @@ jobs: git config user.name "github-actions" git config user.email "actions@github.com" - git pull origin main + git pull origin aquire-lock git add .baseline-lock git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }}" - git push origin main + git push origin aquire-lock env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -86,10 +86,10 @@ jobs: needs: acquire-lock runs-on: ubuntu-latest steps: - - name: Checkout `gi-flow` Branch + - name: Checkout `aquire-lock` Branch uses: actions/checkout@v3 with: - ref: main + ref: aquire-lock - name: Use Node.js uses: actions/setup-node@v3 @@ -104,7 +104,7 @@ jobs: git config user.name "github-actions" git config user.email "actions@github.com" - git pull origin main + git pull origin aquire-lock # Update the lock file with unique content echo "$(date +%s): Updating baselines for PR #${{ github.event.pull_request.number }}" > .baseline-lock @@ -116,7 +116,7 @@ jobs: echo "No changes to commit. Skipping commit." else git commit -m "Lock for baseline update by PR #${{ github.event.pull_request.number }} [skip husky]" - git push origin main + git push origin aquire-lock fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -132,11 +132,11 @@ jobs: git config user.name "github-actions" git config user.email "actions@github.com" - git pull origin main + git pull origin aquire-lock git rm .baseline-lock git commit -m "Release lock for baseline update [skip husky]" - git push origin main + git push origin aquire-lock env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d1f4ad2ed73f21058591220f12258ce57dd9d1fe Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 17:18:50 +0200 Subject: [PATCH 37/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index f4810ee8..766b7cd7 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -140,6 +140,21 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Update Snapshots Check Status + if: success() + run: | + curl -X POST \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{ + "state": "success", + "context": "snapshots-tests", + "description": "Snapshots updated successfully after baseline acceptance.", + "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + }' \ + https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} + + auto-merge: needs: update-baselines runs-on: ubuntu-latest From e1f6235a3485f92e0b2e757169c54493edad46d3 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Tue, 19 Nov 2024 18:53:49 +0200 Subject: [PATCH 38/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 766b7cd7..0eaa19f0 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v3 - name: Verify Required Checks run: | - CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests" and .name != "check-conditions" and .name != "aem-psi-check") | .name') + CHECKS=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state --jq '.[] | select(.state != "SUCCESS" and .name != "snapshots-tests" and .name != "check-conditions" and .name != "auto-merge" and .name != "update-baselines" and .name != "acquire-lock" and .name != "aem-psi-check") | .name') if [ -n "$CHECKS" ]; then echo "Some required checks failed: $CHECKS" exit 1 @@ -153,6 +153,17 @@ jobs: "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" }' \ https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} + + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/OWNER/REPO/statuses/SHA \ + -d '{ + "state":"success", + "target_url":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"The build succeeded!","context":"continuous-integration/jenkins"}' auto-merge: From 6ab9c98a492f4c5e4f21d34f3ef4b9f2c10debd6 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 12:30:17 +0200 Subject: [PATCH 39/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 0eaa19f0..2b77c5ed 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -142,28 +142,16 @@ jobs: - name: Update Snapshots Check Status if: success() - run: | - curl -X POST \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "Content-Type: application/json" \ - -d '{ - "state": "success", - "context": "snapshots-tests", - "description": "Snapshots updated successfully after baseline acceptance.", - "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - }' \ - https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} - run: | curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/OWNER/REPO/statuses/SHA \ + https://api.github.com/repos/bitdefender/www-landing-pages/statuses/${{ github.event.pull_request.head.sha }} \ -d '{ "state":"success", - "target_url":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"The build succeeded!","context":"continuous-integration/jenkins"}' + "target_url":"https://github.com/bitdefender/www-landing-pages/actions/runs/${{ github.run_id }}","description":"The build succeeded!","context":"snapshots-tests"}' auto-merge: From 8fba7bfcdd2d1de3880c00d367fe15c382b6aa37 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 12:41:03 +0200 Subject: [PATCH 40/45] Acquire Lock - switched from main to aquire-lock branch --- ghosti/index.js | 74 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/ghosti/index.js b/ghosti/index.js index 442ba4bf..13409730 100644 --- a/ghosti/index.js +++ b/ghosti/index.js @@ -107,43 +107,43 @@ const EXCLUDED_SNAPSHOT_BLOCKS = [ process.exit(1); } - try { - const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - - // get snapshots tests - const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); - - const batches = createBatches(blockSnapshotsToTest, 3); - - let allTestResults = []; - - for (const batch of batches) { - const snapshotsPromises = batch.map((testName) => { - const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); - if (testAlreadyExists) { - return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { - signal: AbortSignal.timeout(FETCH_TIMEOUT) - }).then((res) => res.json()); - } - console.log('New test was imported', testName); - return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ - name: testName, - startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, - }).generate()) - .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); - }); - - // Await the completion of all promises in the current batch before proceeding to the next - const batchResults = await Promise.all(snapshotsPromises); - allTestResults.push(...batchResults); - } - - // Once all batches are processed, show the full logs of the snapshot tests - showSnapshotTestsFullLogs(allTestResults); - } catch (err) { - console.error(err); - process.exit(1); - } + // try { + // const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); + // + // // get snapshots tests + // const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); + // + // const batches = createBatches(blockSnapshotsToTest, 3); + // + // let allTestResults = []; + // + // for (const batch of batches) { + // const snapshotsPromises = batch.map((testName) => { + // const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + // if (testAlreadyExists) { + // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { + // signal: AbortSignal.timeout(FETCH_TIMEOUT) + // }).then((res) => res.json()); + // } + // console.log('New test was imported', testName); + // return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ + // name: testName, + // startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, + // }).generate()) + // .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); + // }); + // + // // Await the completion of all promises in the current batch before proceeding to the next + // const batchResults = await Promise.all(snapshotsPromises); + // allTestResults.push(...batchResults); + // } + // + // // Once all batches are processed, show the full logs of the snapshot tests + // showSnapshotTestsFullLogs(allTestResults); + // } catch (err) { + // console.error(err); + // process.exit(1); + // } // await new Promise((res) => setTimeout(res, 1000)) })(); From f6056bf94a527a5a247ac0dd89d5fc6d0d11e707 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 13:25:28 +0200 Subject: [PATCH 41/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 2b77c5ed..2447eba7 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -7,6 +7,7 @@ on: permissions: contents: write + statuses: write jobs: check-conditions: @@ -40,7 +41,7 @@ jobs: - name: Verify Approvals run: | APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') - if [[ "$APPROVALS" -lt 2 ]]; then + if [[ "$APPROVALS" -lt 1 ]]; then echo "Not enough approvals. Exiting." exit 1 fi From 7e443d269d71538906fcb855328e5355d0c8d116 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 14:38:23 +0200 Subject: [PATCH 42/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 2447eba7..7a8bf293 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -41,7 +41,7 @@ jobs: - name: Verify Approvals run: | APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') - if [[ "$APPROVALS" -lt 1 ]]; then + if [[ "$APPROVALS" -lt 2 ]]; then echo "Not enough approvals. Exiting." exit 1 fi @@ -152,7 +152,7 @@ jobs: https://api.github.com/repos/bitdefender/www-landing-pages/statuses/${{ github.event.pull_request.head.sha }} \ -d '{ "state":"success", - "target_url":"https://github.com/bitdefender/www-landing-pages/actions/runs/${{ github.run_id }}","description":"The build succeeded!","context":"snapshots-tests"}' + "target_url":"https://github.com/bitdefender/www-landing-pages/actions/runs/${{ github.run_id }}","description":"The build succeeded!","context":"Run Tests and Snapshots / snapshots-tests (pull_request)"}' auto-merge: From 42de58bcbedb5661d261a1359f18e019e685146d Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 15:00:17 +0200 Subject: [PATCH 43/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 34 ++++++++------------------- .github/workflows/run-tests.yml | 2 ++ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 7a8bf293..aec6bfc4 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -41,7 +41,7 @@ jobs: - name: Verify Approvals run: | APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') - if [[ "$APPROVALS" -lt 2 ]]; then + if [[ "$APPROVALS" -lt 1 ]]; then echo "Not enough approvals. Exiting." exit 1 fi @@ -127,41 +127,27 @@ jobs: env: GI_KEY: ${{ secrets.GI_KEY }} + auto-merge: + needs: update-baselines + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Release Lock if: success() run: | git config user.name "github-actions" git config user.email "actions@github.com" - + git pull origin aquire-lock - + git rm .baseline-lock git commit -m "Release lock for baseline update [skip husky]" git push origin aquire-lock env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Update Snapshots Check Status - if: success() - run: | - curl -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/bitdefender/www-landing-pages/statuses/${{ github.event.pull_request.head.sha }} \ - -d '{ - "state":"success", - "target_url":"https://github.com/bitdefender/www-landing-pages/actions/runs/${{ github.run_id }}","description":"The build succeeded!","context":"Run Tests and Snapshots / snapshots-tests (pull_request)"}' - - - auto-merge: - needs: update-baselines - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - name: Auto-Merge PR if: success() run: gh pr merge ${{ github.event.pull_request.number }} --squash --admin diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c61e92d4..fa937ff1 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,6 +22,7 @@ jobs: lint: needs: setup-nodejs runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} steps: - uses: actions/checkout@v3 - run: npm install @@ -30,6 +31,7 @@ jobs: unit-tests: needs: setup-nodejs runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} steps: - uses: actions/checkout@v3 - run: npm install From 6c42d4a8f43cc0cf852306a14b07b55b454d594d Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 16:21:01 +0200 Subject: [PATCH 44/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 4 +- ghosti/index.js | 99 ++++++++++++++------------- ghosti/utils.js | 15 ++++ 3 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 ghosti/utils.js diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index aec6bfc4..46d3890f 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -133,6 +133,8 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v3 + with: + ref: aquire-lock - name: Release Lock if: success() @@ -140,7 +142,7 @@ jobs: git config user.name "github-actions" git config user.email "actions@github.com" - git pull origin aquire-lock + git pull origin aquire-lock --rebase git rm .baseline-lock git commit -m "Release lock for baseline update [skip husky]" diff --git a/ghosti/index.js b/ghosti/index.js index 13409730..4b6c6ea7 100644 --- a/ghosti/index.js +++ b/ghosti/index.js @@ -9,6 +9,7 @@ const { logSuccess, logError } = require('./constants'); +const { fetchWithRetry } = require('./utils'); const GhostInspector = require('ghost-inspector')(process.env.GI_KEY); const hlxEnv = { @@ -75,57 +76,19 @@ const EXCLUDED_SNAPSHOT_BLOCKS = [ } } - try { - const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - // get snapshots tests - const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); - - const snapshotsPromises = blockSnapshotsToTest - .map((testName) => { - const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); - - if (testAlreadyExists) { - return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`).then((res) => res.json()); - } - - return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ - name: testName, - startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, - }).generate()) - .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); - }); - - const [ - snapshotsResult, - ] = await Promise.all([ - Promise.all(snapshotsPromises), - ]); - - showSnapshotTestsFullLogs(snapshotsResult); - } catch (err) { - console.error(err); - process.exit(1); - } - // try { // const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); - // // // get snapshots tests // const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); // - // const batches = createBatches(blockSnapshotsToTest, 3); - // - // let allTestResults = []; - // - // for (const batch of batches) { - // const snapshotsPromises = batch.map((testName) => { + // const snapshotsPromises = blockSnapshotsToTest + // .map((testName) => { // const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + // // if (testAlreadyExists) { - // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { - // signal: AbortSignal.timeout(FETCH_TIMEOUT) - // }).then((res) => res.json()); + // return fetch(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`).then((res) => res.json()); // } - // console.log('New test was imported', testName); + // // return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ // name: testName, // startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, @@ -133,17 +96,55 @@ const EXCLUDED_SNAPSHOT_BLOCKS = [ // .then(({ _id }) => fetch(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); // }); // - // // Await the completion of all promises in the current batch before proceeding to the next - // const batchResults = await Promise.all(snapshotsPromises); - // allTestResults.push(...batchResults); - // } + // const [ + // snapshotsResult, + // ] = await Promise.all([ + // Promise.all(snapshotsPromises), + // ]); // - // // Once all batches are processed, show the full logs of the snapshot tests - // showSnapshotTestsFullLogs(allTestResults); + // showSnapshotTestsFullLogs(snapshotsResult); // } catch (err) { // console.error(err); // process.exit(1); // } + try { + const blockSnapshotsToTest = fs.readdirSync(LOCAL_BLOCKS_PATH).filter(blockName => !EXCLUDED_SNAPSHOT_BLOCKS.includes(blockName)); + + // get snapshots tests + const snapshotSuiteTests = await GhostInspector.getSuiteTests(SNAPSHOTS_SUITE_ID); + + const batches = createBatches(blockSnapshotsToTest, 5); + + let allTestResults = []; + + for (const batch of batches) { + const snapshotsPromises = batch.map((testName) => { + const testAlreadyExists = snapshotSuiteTests.find((originalTest) => originalTest.name === testName); + if (testAlreadyExists) { + return fetchWithRetry(`https://api.ghostinspector.com/v1/tests/${testAlreadyExists._id}/execute/?apiKey=${process.env.GI_KEY}&startUrl=${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testAlreadyExists.name}`, { + signal: AbortSignal.timeout(FETCH_TIMEOUT) + }).then((res) => res.json()); + } + console.log('New test was imported', testName); + return GhostInspector.importTest(SNAPSHOTS_SUITE_ID, new SnapshotBlockTest({ + name: testName, + startUrl: `${featureBranchEnvironmentBaseUrl}/${PATH_TO_BLOCKS}/${testName}`, + }).generate()) + .then(({ _id }) => fetchWithRetry(`https://api.ghostinspector.com/v1/tests/${_id}/execute/?apiKey=${process.env.GI_KEY}`).then((res) => res.json())); + }); + + // Await the completion of all promises in the current batch before proceeding to the next + const batchResults = await Promise.all(snapshotsPromises); + allTestResults.push(...batchResults); + } + + // Once all batches are processed, show the full logs of the snapshot tests + showSnapshotTestsFullLogs(allTestResults); + } catch (err) { + console.error(err); + process.exit(1); + } + // await new Promise((res) => setTimeout(res, 1000)) })(); diff --git a/ghosti/utils.js b/ghosti/utils.js new file mode 100644 index 00000000..be99fb3c --- /dev/null +++ b/ghosti/utils.js @@ -0,0 +1,15 @@ +async function fetchWithRetry(url, options = {}, retries = 3) { + for (let attempt = 1; attempt <= retries; attempt++) { + try { + return await fetch(url, options); + } catch (error) { + if (attempt === retries) throw error; + console.warn(`Retrying fetch... (${attempt}/${retries})`); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + } +} + +module.exports = { + fetchWithRetry +} From 29b5f3ec33ef14bd55d308a919224be19d2f65c3 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Wed, 20 Nov 2024 16:46:29 +0200 Subject: [PATCH 45/45] Acquire Lock - switched from main to aquire-lock branch --- .github/workflows/accept-baseline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/accept-baseline.yml b/.github/workflows/accept-baseline.yml index 46d3890f..40c5ff3f 100644 --- a/.github/workflows/accept-baseline.yml +++ b/.github/workflows/accept-baseline.yml @@ -41,7 +41,7 @@ jobs: - name: Verify Approvals run: | APPROVALS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '[.reviews[] | select(.state=="APPROVED")] | length') - if [[ "$APPROVALS" -lt 1 ]]; then + if [[ "$APPROVALS" -lt 2 ]]; then echo "Not enough approvals. Exiting." exit 1 fi