-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e22e2a
commit 8f35faa
Showing
4 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |