-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TECH-1140 Split workflow into Composite Actions (#48)
- Loading branch information
1 parent
7c3127e
commit f2d96e2
Showing
12 changed files
with
488 additions
and
403 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,16 @@ | ||
name: 'Build and upload Docker Image' | ||
description: 'Build and upload Docker Image to ECR' | ||
inputs: | ||
version: | ||
description: 'Version number of the image released to ECR' | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Build Docker Image | ||
shell: bash | ||
run: | | ||
set -ue ; | ||
./gradlew jib --parallel --continue --stacktrace \ | ||
-Ptag=${{ inputs.version }} \ | ||
-Djib.from.platforms=linux/amd64,linux/arm64 |
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,18 @@ | ||
name: 'Code analysis' | ||
description: 'Run code analysis' | ||
inputs: | ||
secrets: | ||
description: 'Secrets required for the build' | ||
required: true | ||
default: '{}' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Sonar analysis | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ fromJSON(inputs.secrets).GIT_TOKEN }} # Needed to get PR information, if any | ||
SONAR_TOKEN: ${{ fromJSON(inputs.secrets).SONAR_TOKEN }} | ||
run: | | ||
set -ue ; | ||
./gradlew sonar -x test -x behaviourTest -x integrationTest -x jacocoTestReport --parallel --continue --stacktrace |
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,75 @@ | ||
name: 'Deploy to staging' | ||
description: 'Upgrade the staging environment with the latest docker image' | ||
inputs: | ||
secrets: | ||
description: 'Secrets required for the build' | ||
required: true | ||
default: '{}' | ||
version: | ||
description: 'Version number of the image released to ECR' | ||
required: true | ||
default-name: | ||
description: 'Default service and component name to use when not specified in the auto-deployment file' | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: tibdex/github-app-token@v2 | ||
id: generate-token | ||
with: | ||
app_id: ${{ fromJSON(inputs.secrets).AUTODEPLOYER_ID }} | ||
private_key: ${{ fromJSON(inputs.secrets).AUTODEPLOYER_KEY }} | ||
|
||
- name: Trigger deployments | ||
shell: bash | ||
env: | ||
DEPLOYER_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
run: | | ||
set -ue | ||
IMAGE_NAME='${{ inputs.repository-name }}' | ||
VERSION='${{ inputs.version }}' | ||
for env in $( ls auto-deploy/*.env.json ) ; do | ||
ENVIRONMENT=$( jq -r '.environment' "$env" ) | ||
COMPONENT=$( jq -r '.component' "$env" ) | ||
SERVICE=$( jq -r '.service' "$env" ) | ||
if [ -z "$ENVIRONMENT" ] || [ "$ENVIRONMENT" = "null" ] ; then | ||
echo "ERROR: Missing environment in $env" | ||
exit 1 | ||
fi | ||
if [ -z "$COMPONENT" ] || [ "$COMPONENT" = "null" ] ; then | ||
COMPONENT="$REPOSITORY_NAME" | ||
fi | ||
if [ -z "$SERVICE" ]|| [ "$SERVICE" = "null" ] ; then | ||
SERVICE="$REPOSITORY_NAME" | ||
fi | ||
DISPATCH_EVENT="$REPOSITORY_NAME calls update version to $VERSION for $COMPONENT/$SERVICE in $ENVIRONMENT" | ||
BODY='{ | ||
"event_type": "update_version_event", | ||
"client_payload": { | ||
"dispatch_event": "'"$DISPATCH_EVENT"'", | ||
"environment": "'"$ENVIRONMENT"'", | ||
"component": "'"$COMPONENT"'", | ||
"service": "'"$SERVICE"'", | ||
"version": "'"$VERSION"'" | ||
} | ||
}' | ||
echo "$DISPATCH_EVENT" | ||
curl -H "Accept: application/vnd.github.everest-preview+json" \ | ||
-H "Authorization: token ${DEPLOYER_TOKEN}" \ | ||
--request POST \ | ||
--data "${BODY}" \ | ||
https://api.github.com/repos/sympower/environments/dispatches | ||
echo "Done: $DISPATCH_EVENT" | ||
done |
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,30 @@ | ||
name: 'Format version' | ||
description: 'Format version' | ||
inputs: | ||
style-as-release: | ||
description: "true/false flag to format version in release style (yyyy.MM.dd.hh.mm-hash) or as branch reference" | ||
required: true | ||
outputs: | ||
version: | ||
description: Version number of the image released to ECR | ||
value: ${{ steps.format-version.outputs.version }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- id: format-version | ||
name: "Format version" | ||
shell: bash | ||
run: | | ||
set -eu | ||
IS_RELEASE_STYLE='${{ inputs.style-as-release }}' | ||
if [ "$IS_RELEASE_STYLE" = "true" ] ; then | ||
currentDate=$(date +"%Y.%m.%d.%H.%M") ; | ||
tag=$(echo $GITHUB_SHA | cut -c 1-7) ; | ||
echo "version=$(echo $currentDate-$tag)" >> $GITHUB_OUTPUT ; | ||
else | ||
REF_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}} | ||
tag=$(echo ${REF_NAME} | cut -c 1-20 | tr / -) ; | ||
echo "version=$(echo $tag)" >> $GITHUB_OUTPUT ; | ||
fi |
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,92 @@ | ||
name: 'Run Tests' | ||
description: 'Run tests, behaviour tests and integration tests' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Run unit tests | ||
shell: bash | ||
run: ./gradlew test --parallel --continue --stacktrace | ||
|
||
- name: Check test XML files exist | ||
id: search-test-results | ||
shell: bash | ||
run: | | ||
if find . | grep test-results/test | grep -q xml$ ; then | ||
echo "TEST_RESULTS_EXIST=true" >> "$GITHUB_ENV" | ||
else | ||
echo "TEST_RESULTS_EXIST=false" >> "$GITHUB_ENV" | ||
fi | ||
- name: Unit test report | ||
if: env.TEST_RESULTS_EXIST | ||
uses: phoenix-actions/test-reporting@v12 | ||
continue-on-error: true | ||
env: | ||
NODE_OPTIONS: --max-old-space-size=4096 | ||
with: | ||
name: Unit test results | ||
path: '**/test-results/test/*.xml' | ||
reporter: java-junit | ||
fail-on-error: false | ||
output-to: step-summary | ||
|
||
|
||
|
||
- name: Run behaviour tests | ||
shell: bash | ||
run: ./gradlew behaviourTest --parallel --continue --stacktrace | ||
|
||
- name: Check behaviourTest XML files exist | ||
id: search-behaviourTest-results | ||
shell: bash | ||
run: | | ||
if find . | grep test-results/behaviourTest | grep -q xml$ ; then | ||
echo "BEHAVIOUR_TEST_RESULTS_EXIST=true" >> "$GITHUB_ENV" | ||
else | ||
echo "BEHAVIOUR_TEST_RESULTS_EXIST=false" >> "$GITHUB_ENV" | ||
fi | ||
- name: Behaviour test report | ||
if: env.BEHAVIOUR_TEST_RESULTS_EXIST | ||
uses: phoenix-actions/test-reporting@v12 | ||
continue-on-error: true | ||
env: | ||
NODE_OPTIONS: --max-old-space-size=4096 | ||
with: | ||
name: Behaviour test results | ||
path: '**/test-results/behaviourTest/*.xml' | ||
reporter: java-junit | ||
fail-on-error: false | ||
output-to: step-summary | ||
|
||
|
||
- name: Run integration tests | ||
shell: bash | ||
run: ./gradlew integrationTest --parallel --continue --stacktrace | ||
|
||
- name: Check integrationTest XML files exist | ||
id: search-integrationTest-results | ||
shell: bash | ||
run: | | ||
if find . | grep test-results/integrationTest | grep -q xml$ ; then | ||
echo "INTEGRATION_TEST_RESULTS_EXIST=true" >> "$GITHUB_ENV" | ||
else | ||
echo "INTEGRATION_TEST_RESULTS_EXIST=false" >> "$GITHUB_ENV" | ||
fi | ||
- name: Integration test report | ||
if: env.INTEGRATION_TEST_RESULTS_EXIST | ||
uses: phoenix-actions/test-reporting@v12 | ||
continue-on-error: true | ||
env: | ||
NODE_OPTIONS: --max-old-space-size=4096 | ||
with: | ||
name: Integration test results | ||
path: '**/test-results/integrationTest/*.xml' | ||
reporter: java-junit | ||
fail-on-error: false | ||
output-to: step-summary | ||
|
||
- name: Create test reports | ||
shell: bash | ||
run: ./gradlew testCodeCoverageReport behaviourTestCodeCoverageReport integrationTestCodeCoverageReport jacocoTestReport -x test -x behaviourTest -x integrationTest --parallel --continue --stacktrace |
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,73 @@ | ||
name: 'Setup Build Environment' | ||
description: 'Setup OpenJDK, Checkout, Login to AWS ECR' | ||
inputs: | ||
secrets: | ||
description: 'Secrets required for the build' | ||
required: true | ||
default: '{}' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
# Disabling shallow clone is recommended for improving relevancy of reporting | ||
fetch-depth: 0 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
with: | ||
gradle-home-cache-cleanup: true | ||
|
||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.sonar/cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- id: set-environment | ||
name: Set environment | ||
shell: bash | ||
run: | | ||
set -ue ; | ||
mkdir -p ~/.gradle | ||
CONF_FILE=~/.gradle/gradle.properties | ||
echo '# Gradle configuration' > "$CONF_FILE" | ||
echo 'sympowerMavenRepoPublicUrl=${{ fromJSON(inputs.secrets).MAVEN_REPO_PUBLIC_URL }}' >> "$CONF_FILE" | ||
echo 'sympowerMavenRepoSnapshotsUrl=${{ fromJSON(inputs.secrets).MAVEN_REPO_SNAPSHOTS_URL }}' >> "$CONF_FILE" | ||
echo 'sympowerMavenRepoReleasesUrl=${{ fromJSON(inputs.secrets).MAVEN_REPO_RELEASES_URL }}' >> "$CONF_FILE" | ||
echo 'sympowerMavenRepoUsername=${{ fromJSON(inputs.secrets).MAVEN_REPO_USER }}' >> "$CONF_FILE" | ||
echo 'sympowerMavenRepoPassword=${{ fromJSON(inputs.secrets).MAVEN_REPO_PASS }}' >> "$CONF_FILE" | ||
|
||
echo 'pactbroker.url=${{ fromJSON(inputs.secrets).PACT_BROKER_BASE_URL }}' >> "$CONF_FILE" | ||
echo 'pactbroker.auth.username=${{ fromJSON(inputs.secrets).PACT_BROKER_USERNAME }}' >> "$CONF_FILE" | ||
echo 'pactbroker.auth.password=${{ fromJSON(inputs.secrets).PACT_BROKER_PASSWORD }}' >> "$CONF_FILE" | ||
|
||
echo 'registryHost=${{ fromJSON(inputs.secrets).DOCKER_REGISTRY_HOST }}' >> "$CONF_FILE" | ||
|
||
## Configure environment variables | ||
echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV | ||
echo PACT_BROKER_BASE_URL=${{ fromJSON(inputs.secrets).PACT_BROKER_BASE_URL }} >> $GITHUB_ENV | ||
echo PACT_BROKER_USERNAME=${{ fromJSON(inputs.secrets).PACT_BROKER_USERNAME }} >> $GITHUB_ENV | ||
echo PACT_BROKER_PASSWORD=${{ fromJSON(inputs.secrets).PACT_BROKER_PASSWORD }} >> $GITHUB_ENV | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ fromJSON(inputs.secrets).AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ fromJSON(inputs.secrets).AWS_SECRET_ACCESS_KEY }} | ||
aws-region: 'eu-central-1' | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 |
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,27 @@ | ||
name: 'Upload Artifacts' | ||
description: 'Zip and upload build artifacts' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Zip artifacts | ||
shell: bash | ||
if: always() | ||
run: | | ||
set -ue ; | ||
found_files=$(find . -type f -path "*/build/reports/*" -print) | ||
if [ -n "$found_files" ]; then | ||
echo "Directory exists, running zip command..." | ||
echo "$found_files" | xargs zip -r reports.zip | ||
else | ||
echo "Directory does not exist, skipping zip command." | ||
fi | ||
- name: Upload build results | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: results | ||
retention-days: 1 | ||
path: | | ||
reports.zip |
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,26 @@ | ||
name: 'Upload Pacts' | ||
description: 'Upload pacts to the pact broker' | ||
inputs: | ||
version: | ||
description: 'Version pact to be uploaded' | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Upload Pacts | ||
shell: bash | ||
run: | | ||
set -ue ; | ||
for PACT_DIR in $( find . | grep build/pacts$ | sed 's/^.\///' ) ; do | ||
echo "Uploading pacts in: ${PACT_DIR}" | ||
docker run --rm \ | ||
-w ${PWD} \ | ||
-v ${PWD}:${PWD} \ | ||
-e PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_USERNAME \ | ||
-e PACT_BROKER_PASSWORD \ | ||
pactfoundation/pact-cli:0.50.0.27 \ | ||
publish \ | ||
${PWD}/${PACT_DIR} \ | ||
--consumer-app-version "${{ inputs.version }}" | ||
done |
Oops, something went wrong.