Skip to content

bumper wiremock

bumper wiremock #1221

Workflow file for this run

name: Build
on:
push:
branches:
- main
env:
CONTAINER_REGISTRY: europe-north1-docker.pkg.dev
RESOURCE: config/nais.yml
TEAM: tbd
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
jobs:
generate_vars:
runs-on: ubuntu-latest
outputs:
team: ${{ steps.set-vars.outputs.team }}
tag: ${{ steps.set-vars.outputs.tag }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
deployMatrix: ${{ steps.set-matrix.outputs.deployMatrix }}
emptyMatrix: ${{ steps.set-matrix.outputs.emptyMatrix }}
emptyDeployMatrix: ${{ steps.set-matrix.outputs.emptyDeployMatrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: cache gradle wrapper
uses: actions/cache@v4
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
- name: cache gradle caches
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/build.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-caches-
- id: set-vars
name: create docker image SHA part
run: |
echo "team=$TEAM" >> $GITHUB_OUTPUT
echo "tag=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
- id: set-changed-files
name: create CHANGED_FILES
run: |
# create a comma-separated list of changed files
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r $GITHUB_SHA | tr '\r\n' ',' | sed -e 's/,$//')
echo Endrede filer: $CHANGED_FILES
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
- id: set-matrix
name: create matrices
run: |
MATRIX=$(./gradlew -q buildMatrix --console=plain)
DEPLOY_MATRIX=$(./gradlew -q deployMatrix --console=plain)
MATRIX_SIZE=$(echo $MATRIX | jq '.project|length')
DEPLOY_MATRIX_SIZE=$(echo $DEPLOY_MATRIX | jq '.project|length')
if [ "$MATRIX_SIZE" == '0' ]; then
echo "Empty matrix"
echo "matrix=[]" >> $GITHUB_OUTPUT # to prevent error because matrix is empty
echo "emptyMatrix=true" >> $GITHUB_OUTPUT
else
echo Setting matrix to $MATRIX
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
echo "emptyMatrix=false" >> $GITHUB_OUTPUT
fi
if [ "$DEPLOY_MATRIX_SIZE" == '0' ]; then
echo "Empty deploy matrix"
echo "deployMatrix=[]" >> $GITHUB_OUTPUT # to prevent error because matrix is empty
echo "emptyDeployMatrix=true" >> $GITHUB_OUTPUT
else
echo Setting deploy matrix to $DEPLOY_MATRIX
echo "deployMatrix=$DEPLOY_MATRIX" >> $GITHUB_OUTPUT
echo "emptyDeployMatrix=false" >> $GITHUB_OUTPUT
fi
build:
needs: generate_vars
name: build
runs-on: ubuntu-latest
permissions:
packages: write
id-token: write
if: needs.generate_vars.outputs.emptyMatrix == 'false'
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate_vars.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: cache gradle wrapper
uses: actions/cache@v4
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
- name: cache gradle caches
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/build.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-caches-
- name: test and build
run: ./gradlew ${{ matrix.project }}:test ${{ matrix.project }}:build
- name: Check app.jar existence
id: app_jar
uses: andstor/file-existence-action@v3
with:
files: "${{ matrix.project }}/build/libs/app.jar"
- name: build docker image
if: steps.app_jar.outputs.files_exists == 'true'
uses: nais/docker-build-push@v0
id: docker-build-push
with:
team: ${{ needs.generate_vars.outputs.team }}
image_suffix: ${{ matrix.project }}
tag: ${{ needs.generate_vars.outputs.tag }}
dockerfile: Dockerfile
docker_context: ${{ matrix.project }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
- name: lage build-fil
if: ${{ always() }}
run: |
echo oui > "${{ matrix.project }}_build_${{ steps.docker-build-push.outcome }}.txt"
- name: laste opp build-fil
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
overwrite: true
retention-days: 1
name: "${{ matrix.project }}_build_result"
path: "${{ matrix.project }}_build_${{ steps.docker-build-push.outcome }}.txt"
deploy:
needs: [generate_vars, build]
name: deploy
if: always() && needs.generate_vars.outputs.emptyDeployMatrix == 'false'
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate_vars.outputs.deployMatrix) }}
runs-on: ubuntu-latest
steps:
- name: create env vars
run: |
# VARS og IMAGE er miljøvariabler som leses automatisk av nais/deploy/actions/deploy
VARS_FILE="config/${{ matrix.project }}/${{ matrix.cluster }}.yml"
echo "VARS=$VARS_FILE" >> $GITHUB_ENV
echo "IMAGE=${{ env.CONTAINER_REGISTRY }}/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/${{ needs.generate_vars.outputs.team }}/${{ github.event.repository.name }}-${{ matrix.project }}:${{ needs.generate_vars.outputs.tag }}" >> $GITHUB_ENV
- name: Fetch sources
uses: actions/checkout@v4
- name: laste ned build-fil
uses: actions/download-artifact@v4
with:
name: "${{ matrix.project }}_build_result"
- name: ser om vi har nais config og at bygget gikk bra
id: deploy-files
uses: andstor/file-existence-action@v3
with:
files: "${{ env.VARS }}, ${{ matrix.project }}_build_success.txt"
- name: deploy
if: steps.deploy-files.outputs.files_exists == 'true'
uses: nais/deploy/actions/deploy@v2
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: ${{ matrix.cluster }}
VAR: team=${{ needs.generate_vars.outputs.team }},app=${{ matrix.project }}