Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
ci: adjust release and merge main flows (#19)
Browse files Browse the repository at this point in the history
* ci: adjust release and merge main flows

* ci: fix job needs

* New commit to trigger jobs

* ci: fix env name

* ci: add debug mode to codeql
  • Loading branch information
Ricardo Campos authored Aug 24, 2022
1 parent 69d192c commit d261fac
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- name: Initialize
uses: github/codeql-action/init@v2
with:
debug: true
languages: java

- name: Set up JDK 17
Expand Down
62 changes: 54 additions & 8 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ on:
- "**.yaml"

env:
REGISTRY: ghcr.io
NAME: nrbestapi

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# Clean up OpenShift when PR closed, no conditions
cleanup-openshift:
Expand Down Expand Up @@ -84,20 +89,61 @@ jobs:
release_name: ${{ steps.changelog.outputs.tag }}
body: ${{ steps.changelog.outputs.clean_changelog }}

# Promote images when PR merged and branch = main
promote-images:
name: Promote DEV images to TEST
runs-on: ubuntu-latest
# If merged, then handle any image promotion
image-backend:
name: Backend Image Promotion
outputs:
build: ${{ steps.check.outputs.build }}
env:
COMPONENT: backend
PREV: ${{ github.event.number }}
ZONE: test
environment:
name: test
runs-on: ubuntu-22.04
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
steps:
- name: Promote Image to TEST
- name: Check for image changes
id: check
run: |
# Vars
IMG_PREV="${{ env.REGISTRY }}/${{ github.repository }}:${{ env.PREV }}-${{ env.COMPONENT }}"
IMG_ZONE="${{ env.REGISTRY }}/${{ github.repository }}:${{ env.ZONE }}-${{ env.COMPONENT }}"
# Make sure an image exists to promote; grab SHA
if [[ ! $(docker pull "${IMG_PREV}") ]]; then
echo -e "\n No images to promote"
exit 0
fi
SHA_PREV=$(docker inspect -f '{{.Id}}' "${IMG_PREV}")
# Use blank SHA for promoted image, unless a real one exists instead
SHA_ZONE=""
if [[ $(docker pull "${IMG_ZONE}") ]]; then
SHA_ZONE=$(docker inspect -f '{{.Id}}' "${IMG_ZONE}")
fi
# Output SHAs
echo -e "\n${IMG_PREV}: ${SHA_PREV}"
echo -e "${IMG_ZONE}: ${SHA_ZONE}\n"
# If different, then trigger updates
if [[ "${SHA_PREV}" != "${SHA_ZONE}" ]]; then
echo "::set-output name=build::true"
echo "Image has changed"
# Login to OpenShift and select project
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }}
oc project ${{ secrets.OC_NAMESPACE }}
oc delete is/${{ env.NAME }}-${{ env.ZONE}}-${{ env.COMPONENT }} || true
exit 0
fi
echo "Image promotion not required"
- name: Promote Service API Image
if: steps.check.outputs.build == 'true'
uses: shrink/actions-docker-registry-tag@v2
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
repository: ${{ github.repository }}
target: ${{ github.event.number }}-service-api
target: ${{ env.PREV }}-${{ env.COMPONENT }}
tags: |
test-service-api
${{ env.ZONE }}-${{ env.COMPONENT }}
# Notify when PR merged and branch = main
merge-notification:
Expand Down
23 changes: 9 additions & 14 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ env:
REGISTRY: ghcr.io
NAME: nrbestapi

jobs:
cancel-prev-runs:
name: Cancel Previous Runs
runs-on: ubuntu-latest
steps:
- uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pr-validation:
name: Pull Request Label Validation
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,8 +72,6 @@ jobs:
validate:
name: Code validation
runs-on: ubuntu-latest
needs:
- cancel-prev-runs
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v2
Expand Down Expand Up @@ -110,8 +104,8 @@ jobs:
path: target/site/checkstyle.html
retention-days: 5

test:
name: Test Code
sonarcloud:
name: Test Code and Static Analysis
runs-on: ubuntu-latest
needs:
- validate
Expand Down Expand Up @@ -201,6 +195,7 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
debug: true
languages: java

- name: Set up JDK 17
Expand Down Expand Up @@ -231,7 +226,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- security
- test
- sonarcloud
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -275,7 +270,7 @@ jobs:
name: DEV Deployment
needs:
- security
- test
- sonarcloud
- build-service-api
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down

0 comments on commit d261fac

Please sign in to comment.