Skip to content

Commit

Permalink
feat: pr-close workflow (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Feb 14, 2024
1 parent 7e22e2a commit 8f35faa
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 3 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/.pr-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: PR Closed

on:
workflow_call:
inputs:
### Typical / recommended
cleanup:
description: 'Type of cleanup; e.g. helm or label'
required: false
type: string
oc_server:
default: https://api.silver.devops.gov.bc.ca:6443
description: 'OpenShift server'
required: false
type: string
packages:
description: 'Comma-separated list of packages to promote'
required: false
type: string

### Usually a bad idea / not recommended
merge_branch:
description: 'Merge target branch'
required: false
type: string
default: ${{ github.event.repository.default_branch }}
organization:
description: 'GitHub organization; e.g. bcgov'
default: ${{ github.repository_owner }}
required: false
type: string
repository:
description: 'GitHub repository, e.g. quickstart-openshift'
default: ${{ github.event.repository.name }}
required: false
type: string
tag_promote:
description: 'Tag to promote to; e.g. latest, test, demo or prod'
default: latest
required: false
type: string
target:
description: 'Target; e.g. PR number, test or prod'
default: ${{ github.event.number }}
required: false
type: string

secrets:
oc_namespace:
description: 'OpenShift namespace'
required: false
oc_token:
description: 'OpenShift token'
required: false

jobs:
vars:
if: inputs.packages != ''
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.packages.outputs.packages }}
steps:
- id: packages
run: |
echo "packages=$(jq -cn '$ARGS.positional' --args ${{ inputs.packages }})"
echo "packages=$(jq -cn '$ARGS.positional' --args ${{ inputs.packages }})" >> $GITHUB_OUTPUT
retags:
name: Retags
needs: vars
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == '${{ inputs.merge_branch }}'
runs-on: ubuntu-22.04
permissions:
packages: write
strategy:
matrix:
package: ${{ fromJson(needs.vars.outputs.packages) }}
timeout-minutes: 1
steps:
- uses: shrink/actions-docker-registry-tag@v4
with:
registry: ghcr.io
repository: ${{ inputs.organization }}/${{ inputs.repository }}/${{ matrix.package }}
target: ${{ inputs.target }}
tags: ${{ inputs.tag_promote }}

# Clean up OpenShift when PR closed, no conditions
cleanup-openshift:
name: Cleanup OpenShift
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Helm
if: inputs.cleanup == 'helm'
env:
release: ${{ inputs.repository }}-${{ inputs.target }}
run: |
oc login --token=${{ secrets.oc_token }} --server=${{ inputs.oc_server }}
oc project ${{ inputs.oc_namespace }} # Safeguard!
# If found, then remove
helm status ${{ env.release }} && helm uninstall --no-hooks ${{ env.release }} || \
echo "Not found: ${{ env.release }}"
# Remove Bitnami Crunchy PVCs
oc delete pvc data-${{ env.release }}-bitnami-pg-0 || \
echo "Not found: pvc data-${{ env.release }}-bitnami-pg-0"
- name: OpenShift Label
if: inputs.cleanup == 'label'
run: |
oc login --token=${{ secrets.oc_token }} --server=${{ inputs.oc_server }}
oc project ${{ inputs.oc_namespace }} # Safeguard!
# Remove old build runs, build pods and deployment pods
oc delete all,cm,pvc,secret -l app=${{ inputs.repository }}-${{ inputs.target }}
15 changes: 15 additions & 0 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: PR

on:
pull_request:

concurrency:
# Cancel in progress for PR open and close
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

jobs:
test:
name: Test
# uses: bcgov-nr/action-support/.github/workflows/pr-close.yml@main
uses: ./.github/workflows/.pr-close.yml
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Repositories of BC's Natural Resource Ministries
Copyright (c) 2024 Province of British Columbia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# action-pr-close
Common tasks for pull request close, like image promotion and openshift cleanup.
# quickstart-openshift-helpers
Workflows and any other common code used by bcgov/quickstart-openshift (template).

0 comments on commit 8f35faa

Please sign in to comment.