From eaa089bd6ccef8309ad735d9d794d987bbd599b0 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Thu, 18 Jan 2024 10:22:55 -0800 Subject: [PATCH] Consistency and cleanup --- .github/workflows/{tests.yml => analysis.yml} | 0 .../workflows/{merge-main.yml => merge.yml} | 5 +- .github/workflows/pr-open.yml | 21 +--- .github/workflows/schedule-jobs.yml | 4 +- .github/workflows/scheduled.yml | 96 +++++++++++++++++++ 5 files changed, 105 insertions(+), 21 deletions(-) rename .github/workflows/{tests.yml => analysis.yml} (100%) rename .github/workflows/{merge-main.yml => merge.yml} (99%) create mode 100644 .github/workflows/scheduled.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/analysis.yml similarity index 100% rename from .github/workflows/tests.yml rename to .github/workflows/analysis.yml diff --git a/.github/workflows/merge-main.yml b/.github/workflows/merge.yml similarity index 99% rename from .github/workflows/merge-main.yml rename to .github/workflows/merge.yml index b12c31c..64d9f3a 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/merge.yml @@ -95,15 +95,13 @@ jobs: cypress-e2e: name: Cypress end to end test - needs: - - deploys + needs: [deploys] runs-on: ubuntu-22.04 strategy: matrix: browser: [ chrome, firefox, edge ] steps: - uses: actions/checkout@v4 - name: Checkout - uses: cypress-io/github-action@v5 name: Cypress run with: @@ -116,6 +114,7 @@ jobs: name: cypress-screenshots path: ./frontend/cypress/screenshots if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` + deploys-prod: name: PROD Deployments needs: [semantic-version,cypress-e2e] diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index e290a4f..8ffb49f 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -42,14 +42,6 @@ jobs: strategy: matrix: package: [api, frontend, database] - include: - - package: frontend - triggers: ('frontend/') - - package: api - triggers: ('api/') - - package: database - triggers: ('database/') - steps: - uses: actions/checkout@v4 - uses: bcgov-nr/action-builder-ghcr@v2.0.1 @@ -58,7 +50,7 @@ jobs: tag: ${{ github.sha }} tag_fallback: test token: ${{ secrets.GITHUB_TOKEN }} - triggers: ${{ matrix.triggers }} + triggers: ('${{ matrix.package }}/') - uses: shrink/actions-docker-registry-tag@v3 with: @@ -77,12 +69,11 @@ jobs: - name: Deploy to OpenShift shell: bash run: | - # Allow pipefail, since we could be catching oc create errors + # Expand for deployment steps set +o pipefail - # Login to OpenShift (NOTE: project command is a safeguard) oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }} - oc project ${{ vars.oc_namespace }} + oc project ${{ vars.oc_namespace }} # Safeguard! # Deploy Helm Chart cd charts/pubcode @@ -123,15 +114,13 @@ jobs: cypress-e2e: name: Cypress end to end test - needs: - - deploys + needs: [deploys] runs-on: ubuntu-22.04 strategy: matrix: - browser: [ chrome, edge ] + browser: [chrome, edge] steps: - uses: actions/checkout@v4 - name: Checkout - uses: cypress-io/github-action@v5 name: Cypress run with: diff --git a/.github/workflows/schedule-jobs.yml b/.github/workflows/schedule-jobs.yml index e20643b..de2aa63 100644 --- a/.github/workflows/schedule-jobs.yml +++ b/.github/workflows/schedule-jobs.yml @@ -1,4 +1,4 @@ -name: Schedule Jobs +name: Scheduled on: workflow_dispatch: @@ -10,7 +10,7 @@ on: - cron: "0 8 * * *" concurrency: - group: ${{ github.workflow }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml new file mode 100644 index 0000000..e20643b --- /dev/null +++ b/.github/workflows/scheduled.yml @@ -0,0 +1,96 @@ +name: Schedule Jobs + +on: + workflow_dispatch: + inputs: + REPO_NAMES: + required: false + description: comma separated list of repo names within bcgov org. for one of jobs to run for specific repos. + schedule: # * is a special character in YAML, so you have to quote this string, every day at 8am GMT + - cron: "0 8 * * *" + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + +jobs: + pubcode-crawler: + name: Crawl Git Repos for bcgovpubcode.yml + runs-on: ubuntu-22.04 + environment: prod + defaults: + run: + working-directory: crawler + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Add Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + - name: Install Dependencies + run: npm ci + + - uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Process script + env: + GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO_NAMES: ${{ github.event.inputs.REPO_NAMES }} + run: | + oc login --token=${{ secrets.OC_TOKEN }} --server=${{ vars.OC_SERVER }} + oc project ${{ vars.OC_NAMESPACE }} + + # Get API key + API_KEY=$(oc get secrets/pubcode --template={{.data.API_KEY}} | base64 -d) + API_URL=https://$(oc get route/pubcode-api --template={{.spec.host}}) + API_KEY="${API_KEY}" API_URL="${API_URL}" node src/main.js + + validate-ministry-list: + name: Validate Ministry List in the pubcode schema. + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: schema/script + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Add Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + + - name: Install Dependencies + run: npm ci + + - uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Process script + id: validate-ministry-list + run: node ./index.js + + - name: create a branch, commit and push changes + if: steps.validate-ministry-list.outputs.schemaChanged == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + git config --local user.name ${{ github.actor }} + git checkout -b chore/ministry-name-schema + git add ../bcgovpubcode.json + git commit -m "Updating the Schema as changes to ministry names were detected." + git push origin chore/ministry-name-schema + # Create a Pull Request + gh pr create --assignee "mishraomp" --base main --label "chore" --title "Updating the Schema as changes to ministry names were detected." --body "Updating the Schema as changes to ministry names were detected." +