Skip to content

Commit

Permalink
chore(ci): shared and main merge workflows (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Mar 29, 2024
1 parent c2f5467 commit a02dc71
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 73 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: .Deploy

on:
workflow_call:
inputs:
### Required
target:
description: PR number, test or prod
required: true
type: string

### Typical / recommended
environment:
description: GitHub environment; omit for PRs
required: false
type: string

triggers:
description: Bash array to diff for build triggering; omit to always fire
required: false
type: string

verify:
description: Run the cronjob and verify results? [true|false]
required: false
type: boolean
default: true

env:
CRONJOB: ${{ github.event.repository.name }}-${{ inputs.target }}-sync
JOB_JOB: ${{ github.event.repository.name }}-${{ inputs.target }}-sync-${{ github.run_number }}

jobs:
deploy:
name: Deploy
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Deploy
uses: bcgov-nr/action-deployer-openshift@v2.2.0
with:
file: sync/openshift.etl.yml
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
oc_version: 4.13
overwrite: true
parameters: -p ZONE=${{ inputs.target }} -p TAG=${{ inputs.target }}
post_rollout: oc create job ${{ env.JOB_JOB }} --from=cronjob/${{ env.CRONJOB }}
triggers: ${{ inputs.triggers }}

verify:
name: Verify
if: inputs.verify == true
environment: ${{ inputs.environment }}
needs: [deploy]
runs-on: ubuntu-latest
steps:
- name: Verify
run: |
# Check job logs
# Login
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ secrets.oc_namespace }} #Safeguard!
# Follow
oc wait --for=jsonpath='{.status.failed}'=4 job/${{ env.JOB_JOB }} --timeout=1m || true
oc logs -l job-name=${{ env.JOB_JOB }} --tail=50 --follow
# Results and exit code
oc get job ${{ env.JOB_JOB }}
if [ $(oc get job ${{ env.JOB_JOB }} -o jsonpath='{.status.ready}') -eq 0 ]; then
echo "Job failed!"
exit 1
else
echo "Job successful!"
exit 0
fi
24 changes: 21 additions & 3 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,27 @@ jobs:
id: pr
uses: bcgov-nr/action-get-pr@v0.0.1

results:
name: PR Results
deploy:
name: Deploy
needs: [vars]
secrets: inherit
uses: ./.github/workflows/.deploy.yml
with:
environment: test
target: ${{ needs.vars.outputs.pr }}
verify: false

promote:
name: Promote Images
needs: [deploy, vars]
runs-on: ubuntu-22.04
permissions:
packages: write
timeout-minutes: 1
steps:
- run: echo "Workflow completed successfully!"
- uses: shrink/actions-docker-registry-tag@v4
with:
registry: ghcr.io
repository: ${{ github.repository }}/sync
target: ${{ needs.vars.outputs.pr }}
tags: prod
81 changes: 11 additions & 70 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,95 +8,36 @@ concurrency:
group: ${{ github.event.number }}
cancel-in-progress: true

env:
CRONJOB: ${{ github.event.repository.name }}-${{ github.event.number }}-sync

jobs:
# https://github.com/bcgov-nr/action-builder-ghcr
builds:
name: Builds
build:
name: Build
runs-on: ubuntu-22.04
outputs:
digest: ${{ steps.builds.outputs.digest }}
permissions:
packages: write
timeout-minutes: 10
steps:
- uses: bcgov-nr/action-builder-ghcr@v2.0.2
id: builds
with:
keep_versions: 50
package: sync
tag: ${{ github.event.number }}
tag_fallback: latest
triggers: ('sync/')

deploys:
name: Deploys
needs: [builds]
if: needs.builds.outputs.digest != ''
runs-on: ubuntu-latest
steps:
- name: Deploys
uses: bcgov-nr/action-deployer-openshift@v2.2.0
with:
file: sync/openshift.etl.yml
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
oc_version: 4.13
overwrite: true
parameters: -p ZONE=${{ github.event.number }} -p TAG=${{ github.event.number }}
post_rollout:
oc create job ${{ env.CRONJOB }}-${{ github.run_number }} --from=cronjob/${{ env.CRONJOB }} &&
oc get job ${{ env.CRONJOB }}-${{ github.run_number }}

logs:
name: Logs
needs: [deploys]
runs-on: ubuntu-latest
steps:
- name: Override OpenShift version
env:
OC: https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable-4.13/openshift-client-linux.tar.gz
working-directory: /usr/local/bin/
run: |
# Override OpenShift version
curl --silent ${{ env.OC }} | tar -xzvf - oc
oc version
- name: Logs
run: |
# Check job logs
# Login$
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ secrets.oc_namespace }} #Safeguard!
# Follow
oc create job ${{ env.CRONJOB }}-${{ github.run_number }} --from=cronjob/${{ env.CRONJOB }}
sleep 15
oc logs -l job-name=${{ env.CRONJOB }}-${{ github.run_number }} --tail=50 --follow
# Results and exit code
oc get job ${{ env.CRONJOB }}-${{ github.run_number }}
READY=$(oc get job ${{ env.CRONJOB }}-${{ github.run_number }} -o jsonpath='{.status.ready}')
echo "READY: $READY"
if [ $(oc get job ${{ env.CRONJOB }}-${{ github.run_number }} -o jsonpath='{.status.ready}') -eq 0 ]; then
if [ "${READY}" -eq 0 ]; then
echo "Job failed!"
exit 1
else
echo "Job successful!"
exit 0
fi
deploy:
name: Deploy
if: needs.build.outputs.digest != ''
needs: [build]
secrets: inherit
uses: ./.github/workflows/.deploy.yml
with:
target: ${{ github.event.number }}

results:
name: PR Results
if: always() && !failure()
needs: [logs]
needs: [deploy]
runs-on: ubuntu-22.04
steps:
- run: echo "Workflow completed successfully!"

0 comments on commit a02dc71

Please sign in to comment.