Skip to content
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
Merged
Show file tree
Hide file tree
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 Oct 13, 2023
78405b0
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
0d11a48
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
dd144b7
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
c9fb700
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
d053d56
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
01a7ec6
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
e71f6a7
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
65b1145
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
c9c54e5
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
0729000
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
502caab
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
41225d8
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 13, 2023
a54b2ca
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 16, 2023
04f5897
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 16, 2023
c01fdce
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 16, 2023
7ce12c1
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 16, 2023
f1516cc
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 16, 2023
78675d3
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
15a5365
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
1691c79
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
bded72e
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
c2f16e3
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
b8db2e6
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
f71eea2
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
5f7a552
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
5caf966
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
15337c8
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
4820817
TECH-1140 Split Workflow into Composite Actions
tonisojandu-sympower Oct 17, 2023
7c6f4a5
TECH-1140 Code review changes
tonisojandu-sympower Oct 18, 2023
4f32dac
TECH-1140 Code review changes
tonisojandu-sympower Oct 18, 2023
379ac1b
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
885d827
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
a0a1ed8
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
f509ac0
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
ee124f2
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
3a0954a
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
3b124ed
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
b95a425
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
69bbb1b
TECH-1140 Code review changes
tonisojandu-sympower Oct 19, 2023
f66ed56
TECH-1140 Code review changes
tonisojandu-sympower Oct 20, 2023
73d85e8
TECH-1140 Code review changes
tonisojandu-sympower Oct 23, 2023
e3add7f
TECH-1140 Code review changes
tonisojandu-sympower Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/actions/build-and-upload-docker-image/action.yml
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
18 changes: 18 additions & 0 deletions .github/actions/code-analysis/action.yml
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
75 changes: 75 additions & 0 deletions .github/actions/deploy-staging/action.yml
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
30 changes: 30 additions & 0 deletions .github/actions/format-version/action.yml
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
92 changes: 92 additions & 0 deletions .github/actions/run-tests/action.yml
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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

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
73 changes: 73 additions & 0 deletions .github/actions/setup-build-environment/action.yml
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
27 changes: 27 additions & 0 deletions .github/actions/upload-build-artifacts/action.yml
florianbuth-sympower marked this conversation as resolved.
Show resolved Hide resolved
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
26 changes: 26 additions & 0 deletions .github/actions/upload-pacts/action.yml
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
Loading