diff --git a/.github/scripts/generate_latest_report_redirect.sh b/.github/scripts/generate_latest_report_redirect.sh index 688e61239..acf5187d7 100644 --- a/.github/scripts/generate_latest_report_redirect.sh +++ b/.github/scripts/generate_latest_report_redirect.sh @@ -11,7 +11,7 @@ cat < build/index.html - + Redirecting... diff --git a/.github/scripts/generate_report_details.sh b/.github/scripts/generate_report_details.sh index bf8131959..dff702fb2 100644 --- a/.github/scripts/generate_report_details.sh +++ b/.github/scripts/generate_report_details.sh @@ -1,12 +1,12 @@ #!/bin/bash -if [[ ! -d "gh-pages/$REPORT_NAME" ]]; then +if [[ ! -d "gh-pages/$GROUP_NAME/$REPORT_NAME" ]]; then latest_number=0 else - gh_pages_content=$(ls "gh-pages/$REPORT_NAME/") + gh_pages_content=$(ls "gh-pages/$GROUP_NAME/$REPORT_NAME/") latest_number=$(echo "$gh_pages_content" | grep -Eo '[0-9]+' | sort -nr | head -n 1) fi echo "report_number=$((latest_number+1))" >> $GITHUB_OUTPUT -echo "report_url=https://$(dirname "$GH_PAGES").github.io/$(basename "$GH_PAGES")/$REPORT_NAME" >> $GITHUB_OUTPUT +echo "report_url=https://$(dirname "$GH_PAGES").github.io/$(basename "$GH_PAGES")/$GROUP_NAME/$REPORT_NAME" >> $GITHUB_OUTPUT diff --git a/.github/scripts/register_report.sh b/.github/scripts/register_report.sh deleted file mode 100644 index 959368afb..000000000 --- a/.github/scripts/register_report.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -PROJECT_DIR="project" -PROJECT_FILE="projects.txt" - -mkdir -p "$PROJECT_DIR" -cp -r gh-pages/* "$PROJECT_DIR" || true - -if grep -q "$REPORT_NAME" "$PROJECT_DIR/$PROJECT_FILE"; then - echo "Project already exists" - echo "project_exists=true">> $GITHUB_OUTPUT -else - echo "\n$REPORT_NAME" >> "$PROJECT_DIR/$PROJECT_FILE" - echo "project_exists=false">> $GITHUB_OUTPUT -fi diff --git a/.github/scripts/remove_oldest_report.sh b/.github/scripts/remove_oldest_report.sh index e0a809604..208f0d9a9 100644 --- a/.github/scripts/remove_oldest_report.sh +++ b/.github/scripts/remove_oldest_report.sh @@ -1,7 +1,7 @@ #!/bin/bash -if [ -d "gh-pages/$REPORT_NAME" ]; then - cd gh-pages/$REPORT_NAME +if [ -d "gh-pages/$GROUP_NAME/$REPORT_NAME" ]; then + cd gh-pages/$GROUP_NAME/$REPORT_NAME # Count the number of numerical directories dir_count=$(find . -maxdepth 1 -type d -regex './[0-9]+' | wc -l) diff --git a/.github/scripts/set_commit_status.sh b/.github/scripts/set_commit_status.sh index f22c4e885..fec4e145b 100644 --- a/.github/scripts/set_commit_status.sh +++ b/.github/scripts/set_commit_status.sh @@ -48,9 +48,9 @@ fi # Determine target URL based on environment case "$GH_PAGES" in - "IntersectMBO/govtool-test-reports") TARGET_URL="https://intersectmbo.github.io/govtool-test-reports/${REPORT_NAME}/${REPORT_NUMBER}" ;; - "cardanoapi/govtool-test-reports") TARGET_URL="https://cardanoapi.github.io/govtool-test-reports/${REPORT_NAME}/${REPORT_NUMBER}" ;; - *) TARGET_URL="https://intersectmbo.github.io/govtool-test-reports/${REPORT_NAME}/${REPORT_NUMBER}" ;; + "IntersectMBO/govtool-test-reports") TARGET_URL="https://intersectmbo.github.io/govtool-test-reports/${GROUP_NAME}/${REPORT_NAME}/${REPORT_NUMBER}" ;; + "cardanoapi/govtool-test-reports") TARGET_URL="https://cardanoapi.github.io/govtool-test-reports/${GROUP_NAME}/${REPORT_NAME}/${REPORT_NUMBER}" ;; + *) TARGET_URL="https://intersectmbo.github.io/govtool-test-reports/${GROUP_NAME}/${REPORT_NAME}/${REPORT_NUMBER}" ;; esac # Determine test result message diff --git a/.github/scripts/set_deployment_environment.sh b/.github/scripts/set_deployment_environment.sh new file mode 100644 index 000000000..8c9495a57 --- /dev/null +++ b/.github/scripts/set_deployment_environment.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +DEPLOYMENT=${DEPLOYMENT:-"govtool.cardanoapi.io/api"} +GROUP_NAME="qa" + +if [[ "$DEPLOYMENT" == "preview.gov.tools" || "$DEPLOYMENT" == "be.preview.gov.tools" || "$DEPLOYMENT" == "z6b8d2f7a-zca4a4c45-gtw.z937eb260.rustrocks.fr" ]]; then + GROUP_NAME="preview" +elif [[ "$DEPLOYMENT" == "gov.tools" || "$DEPLOYMENT" == "be.gov.tools" ]]; then + GROUP_NAME="mainnet" +elif [[ "$DEPLOYMENT" == "p80-z78acf3c2-zded6a792-gtw.z937eb260.rustrocks.fr" || "$DEPLOYMENT" == "z78acf3c2-z5575152b-gtw.z937eb260.rustrocks.fr" ]]; then + GROUP_NAME="dev" +else + GROUP_NAME="qa" +fi + +# Set environment variable for GitHub Actions +echo "GROUP_NAME=${GROUP_NAME}" >>$GITHUB_ENV +echo "group_name=${GROUP_NAME}" >>$GITHUB_OUTPUT +echo "Setting deployment environment to: ${GROUP_NAME}" diff --git a/.github/workflows/test_backend.yml b/.github/workflows/test_backend.yml index 74b9ca195..4acbf9ced 100644 --- a/.github/workflows/test_backend.yml +++ b/.github/workflows/test_backend.yml @@ -33,7 +33,7 @@ on: workflow_run: workflows: ["Build and deploy GovTool test stack"] types: [completed] - branches: + branches: - test - infra/test-chores @@ -59,6 +59,7 @@ jobs: - name: Set pending commit status id: set-pending-status + if: ${{ !github.event.schedule }} run: | echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT curl -X POST -H "Authorization: Bearer ${{ github.token }}" \ @@ -121,27 +122,18 @@ jobs: repository: ${{vars.GH_PAGES}} ssh-key: ${{ secrets.DEPLOY_KEY }} + - name: Set Deployment Environment + id: set-deployment-url + run: | + chmod +x .github/scripts/set_deployment_environment.sh + .github/scripts/set_deployment_environment.sh + - name: Remove oldest report to save space if: ${{success()}} run: | chmod +x .github/scripts/remove_oldest_report.sh .github/scripts/remove_oldest_report.sh - - name: Register report - id: register-project - if: ${{success()}} - run: | - chmod +x .github/scripts/register_report.sh - .github/scripts/register_report.sh - - - if: steps.register-project.outputs.project_exists != 'true' - uses: JamesIves/github-pages-deploy-action@v4 - with: - ssh-key: ${{ secrets.DEPLOY_KEY }} - repository-name: ${{vars.GH_PAGES}} - branch: gh-pages - folder: project - - name: Generate report details id: report-details run: | @@ -153,7 +145,7 @@ jobs: id: allure-report with: allure_results: allure-results - gh_pages: gh-pages/${{env.REPORT_NAME}} + gh_pages: gh-pages/${{steps.set-deployment-url.outputs.group_name}}/${{env.REPORT_NAME}} allure_report: allure-report allure_history: allure-history keep_reports: 2000 @@ -172,7 +164,7 @@ jobs: repository-name: ${{vars.GH_PAGES}} branch: gh-pages folder: build - target-folder: ${{ env.REPORT_NAME }} + target-folder: ${{steps.set-deployment-url.outputs.group_name}}/${{ env.REPORT_NAME }} publish-status: runs-on: ubuntu-latest @@ -185,8 +177,9 @@ jobs: with: name: allure-results path: allure-results + - name: Set Commit Status - if: always() + if: always() && !github.event.schedule run: | chmod +x .github/scripts/set_commit_status.sh .github/scripts/set_commit_status.sh @@ -198,6 +191,7 @@ jobs: env: BASE_URL: https://${{github.event.schedule && 'be.preview.gov.tools' || inputs.deployment || 'govtool.cardanoapi.io/api' }} + DEPLOYMENT: ${{ inputs.deployment || 'govtool.cardanoapi.io/api'}} REPORT_NAME: ${{ github.event.schedule && 'nightly-'}}govtool-backend GH_PAGES: ${{vars.GH_PAGES}} COMMIT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} diff --git a/.github/workflows/test_integration_playwright.yml b/.github/workflows/test_integration_playwright.yml index 841357529..f2eaffda3 100644 --- a/.github/workflows/test_integration_playwright.yml +++ b/.github/workflows/test_integration_playwright.yml @@ -59,6 +59,7 @@ jobs: with: ref: ${{ env.COMMIT_SHA }} - name: Set pending commit status + if: ${{ !github.event.schedule }} id: set-pending-status run: | echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT @@ -136,7 +137,7 @@ jobs: FAUCET_ADDRESS: ${{vars.FAUCET_ADDRESS}} CARDANOAPI_METADATA_URL: ${{vars.CARDANOAPI_METADATA_URL}} FAUCET_PAYMENT_PRIVATE: ${{secrets.FAUCET_PAYMENT_PRIVATE}} - FAUCET_STAKE_PKH: ${{secrets.FAUCET_STAKE_PKH}} + FAUCET_STAKE_PRIVATE: ${{secrets.FAUCET_STAKE_PRIVATE}} publish-report: runs-on: ubuntu-latest @@ -161,27 +162,18 @@ jobs: repository: ${{vars.GH_PAGES}} ssh-key: ${{ secrets.DEPLOY_KEY }} + - name: Set Deployment Environment + id: set-deployment-url + run: | + chmod +x .github/scripts/set_deployment_environment.sh + .github/scripts/set_deployment_environment.sh + - name: Remove oldest report to save space if: ${{success()}} run: | chmod +x .github/scripts/remove_oldest_report.sh .github/scripts/remove_oldest_report.sh - - name: Register report - id: register-project - if: ${{success()}} - run: | - chmod +x .github/scripts/register_report.sh - .github/scripts/register_report.sh - - - if: steps.register-project.outputs.project_exists != 'true' - uses: JamesIves/github-pages-deploy-action@v4 - with: - ssh-key: ${{ secrets.DEPLOY_KEY }} - repository-name: ${{vars.GH_PAGES}} - branch: gh-pages - folder: project - - name: Generate report details id: report-details run: | @@ -194,7 +186,7 @@ jobs: id: allure-report with: allure_results: allure-results - gh_pages: gh-pages/${{env.REPORT_NAME}} + gh_pages: gh-pages/${{steps.set-deployment-url.outputs.group_name}}/${{env.REPORT_NAME}} allure_report: allure-report allure_history: allure-history keep_reports: 2000 @@ -213,7 +205,7 @@ jobs: repository-name: ${{vars.GH_PAGES}} branch: gh-pages folder: build - target-folder: ${{ env.REPORT_NAME }} + target-folder: ${{steps.set-deployment-url.outputs.group_name}}/${{ env.REPORT_NAME }} publish-status: runs-on: ubuntu-latest @@ -226,8 +218,9 @@ jobs: with: name: allure-results path: allure-results + - name: Set Commit Status - if: always() + if: always() && !github.event.schedule run: | chmod +x .github/scripts/set_commit_status.sh .github/scripts/set_commit_status.sh