-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: suppport passing custom environment variables
...to service workflows. Also refactored service workflows to use one common base workflow similar to the library builds.
- Loading branch information
Showing
3 changed files
with
161 additions
and
125 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
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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
gradle-tasks: | ||
description: Tasks to run | ||
required: true | ||
type: string | ||
java-version: | ||
description: Java version to use for build | ||
required: true | ||
type: string | ||
notify-failure: | ||
description: Notify on build failure to Slack | ||
default: true | ||
type: boolean | ||
expect-tests: | ||
description: If JUnit test results are expected | ||
default: true | ||
type: boolean | ||
image-tag: | ||
description: Image tag to scan after build | ||
required: true | ||
type: string | ||
multi-module: | ||
description: If this is a multi-module project | ||
type: boolean | ||
default: false | ||
secrets: | ||
# GH_PAT: | ||
# required: true | ||
DOCKER_HUB_USERNAME: | ||
required: true | ||
DOCKER_HUB_PASSWORD: | ||
required: true | ||
DOCKER_HUB_EMAIL: | ||
WETF_ARTIFACTORY_USER: | ||
WETF_ARTIFACTORY_PASSWORD: | ||
ENV_VARS: # secret for passing on additional env variables based on https://github.com/orgs/community/discussions/26671#discussioncomment-6776498 | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# For each environment variable's key-value pair, mask the value from logs. | ||
- name: Populate custom environment variables | ||
id: environment_variables | ||
env: | ||
env_vars: ${{ secrets.ENV_VARS }} | ||
run: | | ||
if [ -z "$env_vars" ]; then | ||
exit 0 | ||
else | ||
# Iterate over all key-value pairs passed into this workflow and | ||
# add them as environment variables for use in subsequent steps. | ||
# Keys prefixed with "BASE64_" will be decoded from base64 and the | ||
# prefix will be removed. E.g., "BASE64_KEY=value" becomes "KEY=value". | ||
for i in $env_vars; do | ||
if [[ $i == BASE64_* ]]; then i=$(echo $i | sed 's/^BASE64_//g' | sed 's/=.*//g')=$(echo ${i#*=} | base64 -di | base64 -di); fi | ||
echo ::add-mask::${i#*=} | ||
printf '%s\n' "$i" >> $GITHUB_ENV | ||
done | ||
fi | ||
# | ||
# Build, test and create Docker image | ||
# | ||
|
||
- uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: ${{ inputs.java-version }} | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Build and test with Gradle | ||
env: | ||
ORG_GRADLE_PROJECT_wetfArtifactoryUser: ${{ secrets.WETF_ARTIFACTORY_USER }} | ||
ORG_GRADLE_PROJECT_wetfArtifactoryPassword: ${{ secrets.WETF_ARTIFACTORY_PASSWORD }} | ||
ORG_GRADLE_PROJECT_dockerHubUsername: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
ORG_GRADLE_PROJECT_dockerHubPassword: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
ORG_GRADLE_PROJECT_dockerHubEmail: ${{ secrets.DOCKER_HUB_EMAIL }} | ||
ORG_GRADLE_PROJECT_dockerHost: "unix:///var/run/docker.sock" | ||
run: ./gradlew ${{ inputs.gradle-tasks }} | ||
|
||
- name: Upload Gradle test reports | ||
uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: Gradle test reports | ||
retention-days: 7 | ||
path: | | ||
${{ inputs.multi-module && '*/build/reports/tests' || 'build/reports/tests' }} | ||
# | ||
# Security scans | ||
# | ||
|
||
- name: Make sure test-results folder exists | ||
run: mkdir -p ${{ inputs.multi-module && 'trivy-gha-scan/build/test-results' || 'build/test-results' }} | ||
|
||
- name: Vulnerability scan | ||
uses: wetransform/gha-trivy@master | ||
with: | ||
image-ref: 'docker.io/${{ inputs.image-tag }}' | ||
junit-test-output: "${{ inputs.multi-module && 'trivy-gha-scan/build/test-results/trivy.xml' || 'build/test-results/trivy.xml' }}" # added to unit test report | ||
report-retention-days: 30 | ||
|
||
# | ||
# Report on unit tests and critical vulnerabilities | ||
# | ||
|
||
# https://github.com/marketplace/actions/junit-report-action | ||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v3 | ||
if: always() # always run even if the previous step fails | ||
with: | ||
report_paths: "${{ inputs.multi-module && '*/build/test-results/**/*.xml' || 'build/test-results/**/*.xml' }}" | ||
require_tests: ${{ inputs.expect-tests }} | ||
|
||
# Workaround for check that is additionally created being associated | ||
# to the wrong workflow/run. Instead not additional check is created. | ||
# See https://github.com/mikepenz/action-junit-report/issues/40 | ||
annotate_only: true | ||
detailed_summary: true | ||
fail_on_failure: true # in case of critical security vulnerabilities, also required for Slack notification if only tests fail | ||
|
||
# | ||
# Report build failure to Slack | ||
# | ||
|
||
# https://github.com/marketplace/actions/slack-notify-build | ||
- name: Notify slack fail | ||
if: ${{ inputs.notify-failure && failure() }} | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }} | ||
uses: voxmedia/github-action-slack-notify-build@v1 | ||
with: | ||
channel: build-failures | ||
status: FAILED | ||
color: danger |