Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: workflow and process updates #126

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 16 additions & 33 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Merge to Main
name: Merge

on:
push:
branches:
- main
branches: [main]
paths-ignore:
- ".github/ISSUE_TEMPLATE/*"
- "**.md"
Expand All @@ -14,33 +13,19 @@ concurrency:
cancel-in-progress: true

jobs:
codeql:
name: Semantic Code Analysis
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
security-events: write
init:
name: Initialize
outputs:
pr: ${{ steps.pr.outputs.pr }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Initialize
uses: github/codeql-action/init@v3
with:
languages: javascript

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
# Get PR number for squash merges to main
- id: pr
uses: bcgov-nr/[email protected]

deploys-test:
name: TEST Deployments
needs:
- codeql
needs: [init]
environment: test
runs-on: ubuntu-24.04
strategy:
Expand All @@ -59,7 +44,7 @@ jobs:
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: ${{ matrix.overwrite }}
parameters:
-p ZONE=test -p TAG=test
-p ZONE=test -p TAG=${{ needs.init.outputs.pr }}
${{ matrix.parameters }}
-p IDIM_WEB_SERVICE_URL=${{ vars.IDIM_WEB_SERVICE_URL }}
-p IDIM_WEB_SERVICE_ID=${{ secrets.IDIM_WEB_SERVICE_ID }}
Expand All @@ -70,8 +55,7 @@ jobs:

deploys-prod:
name: PROD Deployments
needs:
- deploys-test
needs: [init, deploys-test]
environment: prod
runs-on: ubuntu-24.04
strategy:
Expand All @@ -90,7 +74,7 @@ jobs:
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: ${{ matrix.overwrite }}
parameters:
-p ZONE=prod -p TAG=prod
-p ZONE=prod -p TAG=${{ needs.init.outputs.pr }}
${{ matrix.parameters }}
-p IDIM_WEB_SERVICE_URL=${{ vars.IDIM_WEB_SERVICE_URL }}
-p IDIM_WEB_SERVICE_ID=${{ secrets.IDIM_WEB_SERVICE_ID }}
Expand All @@ -101,8 +85,7 @@ jobs:

image-promotions:
name: Promote images to PROD
needs:
- deploys-prod
needs: [init, deploys-prod]
runs-on: ubuntu-24.04
permissions:
packages: write
Expand All @@ -114,5 +97,5 @@ jobs:
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.component }}
target: test
target: ${{ needs.init.outputs.pr }}
tags: prod
49 changes: 10 additions & 39 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,20 @@ name: Pull Request Closed

on:
pull_request:
types:
- closed
types: [closed]

concurrency:
# PR open and close use the same group, allowing only one at a time
group: pr-${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

jobs:
# Clean up OpenShift when PR closed, no conditions
cleanup-openshift:
name: Cleanup OpenShift
runs-on: ubuntu-24.04
steps:
- name: Install CLI tools from OpenShift Mirror
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4.14.37"

- name: Remove OpenShift artifacts
run: |
# OC Login
OC_TEMP_TOKEN=$(curl -k -X POST https://api.silver.devops.gov.bc.ca:6443/api/v1/namespaces/${{ vars.OC_NAMESPACE }}/serviceaccounts/pipeline/token --header "Authorization: Bearer ${{ secrets.OC_TOKEN }}" -d '{"spec": {"expirationSeconds": 600}}' -H 'Content-Type: application/json; charset=utf-8' | jq -r '.status.token' )
oc login --token=${OC_TEMP_TOKEN} --server=https://api.silver.devops.gov.bc.ca:6443
oc project ${{ vars.OC_NAMESPACE }} # Safeguard!

# Remove old build runs, build pods and deployment pods
oc delete all,pvc,secret -l app=${{ github.event.repository.name }}-${{ github.event.number }}

# If merged into main, then handle any image promotions
image-promotions:
name: Image Promotions
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-24.04
permissions:
packages: write
strategy:
matrix:
package: [backend]
steps:
- uses: shrink/actions-docker-registry-tag@v4
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.package }}
target: ${{ github.event.number }}
tags: test
cleanup:
name: Cleanup and Images
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
cleanup: label
packages: backend
30 changes: 2 additions & 28 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@ concurrency:
cancel-in-progress: true

jobs:
pr-greeting:
name: PR Greeting
if: github.event.action == 'opened' || github.event.action == 'reopened'
env:
DOMAIN: apps.silver.devops.gov.bc.ca
PREFIX: ${{ github.event.repository.name }}-${{ github.event.number }}
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
- name: PR Greeting
uses: bcgov-nr/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
add_markdown: |
---

Thanks for the PR!

Any successful deployments (not always required) will be available below.
[Backend](https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }}/api) available

Once merged, code will be promoted and handed off to following workflow run.
[Main Merge Workflow](https://github.com/${{ github.repository }}/actions/workflows/merge-main.yml)

builds:
name: Builds
runs-on: ubuntu-24.04
Expand All @@ -53,7 +28,7 @@ jobs:
with:
package: ${{ matrix.package }}
tag: ${{ github.event.number }}
tag_fallback: test
tag_fallback: latest
token: ${{ secrets.GITHUB_TOKEN }}
triggers: ${{ matrix.triggers }}
build_file: ${{ matrix.build_file }}
Expand All @@ -62,8 +37,7 @@ jobs:

deploys:
name: Deploys
needs:
- builds
needs: builds
runs-on: ubuntu-24.04
strategy:
matrix:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/pr-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PR Validate

on:
pull_request:
types: [edited, opened, synchronize, reopened, ready_for_review]

concurrency:
group: ${{ github.workflow }}-edit-${{ github.event.number }}
cancel-in-progress: true

jobs:
validate:
name: Validate PR
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
with:
markdown_links: |
- [Backend](https://${{ github.event.repository.name }}-${{ github.event.number }}-backend.apps.silver.devops.gov.bc.ca/api) available

results:
name: Validate Results
if: always() && (!failure()) && (!cancelled())
needs: [validate]
runs-on: ubuntu-24.04
steps:
- run: echo "Success!"
Loading