-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TECH-1140 Split workflow into Composite Actions #48
Merged
tonisojandu-sympower
merged 43 commits into
main
from
TECH-1140-split-workflow-into-composite-actions
Oct 23, 2023
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
8c5988a
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 78405b0
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 0d11a48
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower dd144b7
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower c9fb700
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower d053d56
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 01a7ec6
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower e71f6a7
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 65b1145
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower c9c54e5
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 0729000
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 502caab
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 41225d8
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower a54b2ca
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 04f5897
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower c01fdce
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 7ce12c1
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower f1516cc
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 78675d3
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 15a5365
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 1691c79
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower bded72e
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower c2f16e3
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower b8db2e6
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower f71eea2
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 5f7a552
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 5caf966
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 15337c8
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 4820817
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower 7c6f4a5
TECH-1140 Code review changes
tonisojandu-sympower 4f32dac
TECH-1140 Code review changes
tonisojandu-sympower 379ac1b
TECH-1140 Code review changes
tonisojandu-sympower 885d827
TECH-1140 Code review changes
tonisojandu-sympower a0a1ed8
TECH-1140 Code review changes
tonisojandu-sympower f509ac0
TECH-1140 Code review changes
tonisojandu-sympower ee124f2
TECH-1140 Code review changes
tonisojandu-sympower 3a0954a
TECH-1140 Code review changes
tonisojandu-sympower 3b124ed
TECH-1140 Code review changes
tonisojandu-sympower b95a425
TECH-1140 Code review changes
tonisojandu-sympower 69bbb1b
TECH-1140 Code review changes
tonisojandu-sympower f66ed56
TECH-1140 Code review changes
tonisojandu-sympower 73d85e8
TECH-1140 Code review changes
tonisojandu-sympower e3add7f
TECH-1140 Code review changes
tonisojandu-sympower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
florianbuth-sympower marked this conversation as resolved.
Show resolved
Hide resolved
|
florianbuth-sympower marked this conversation as resolved.
Show resolved
Hide resolved
|
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() | ||
florianbuth-sympower marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify if and where this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy-pasted from the
run-tests
workflow. Maybe @simon-karlsson know.s