|
| 1 | + |
| 2 | +name: 111 Adaptor Build Workflow |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + branches: |
| 7 | + - master |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - master |
| 11 | + |
| 12 | +jobs: |
| 13 | + checkstyle: |
| 14 | + name: Checkstyle |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout Repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Setup Java 21 LTS |
| 21 | + uses: actions/setup-java@v4 |
| 22 | + with: |
| 23 | + java-version: 21 |
| 24 | + distribution: 'temurin' |
| 25 | + |
| 26 | + - name: Checkstyle |
| 27 | + run: | |
| 28 | + ./gradlew checkStyleMain checkstyleTest checkstyleIntegrationTest --parallel |
| 29 | + working-directory: ./service |
| 30 | + |
| 31 | + - name: Collect Artifacts |
| 32 | + if: always() |
| 33 | + run: | |
| 34 | + mkdir -p artifacts |
| 35 | + cp -r ./service/build/reports ./artifacts |
| 36 | +
|
| 37 | + - name: Upload Artifacts |
| 38 | + uses: actions/upload-artifact@v4 |
| 39 | + if: always() |
| 40 | + with: |
| 41 | + name: 'Checkstyle Reports' |
| 42 | + path: ./artifacts/** |
| 43 | + compression-level: 9 |
| 44 | + |
| 45 | + - name: Temporary Artifacts Cleanup |
| 46 | + run: rm -rf ./artifacts |
| 47 | + |
| 48 | + spotbugs: |
| 49 | + name: Spotbugs |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - name: Checkout Repository |
| 53 | + uses: actions/checkout@v4 |
| 54 | + |
| 55 | + - name: Setup Java 21 LTS |
| 56 | + uses: actions/setup-java@v4 |
| 57 | + with: |
| 58 | + java-version: 21 |
| 59 | + distribution: 'temurin' |
| 60 | + |
| 61 | + - name: Spotbugs |
| 62 | + run: | |
| 63 | + ./gradlew spotbugsMain spotbugsTest spotbugsIntegrationTest --parallel |
| 64 | + working-directory: ./service |
| 65 | + |
| 66 | + - name: Collect Artifacts |
| 67 | + if: always() |
| 68 | + run: | |
| 69 | + mkdir -p artifacts |
| 70 | + cp -r ./service/build/reports ./artifacts |
| 71 | +
|
| 72 | + - name: Upload Artifacts |
| 73 | + uses: actions/upload-artifact@v4 |
| 74 | + if: always() |
| 75 | + with: |
| 76 | + name: 'Spotbugs Reports' |
| 77 | + path: ./artifacts/** |
| 78 | + compression-level: 9 |
| 79 | + |
| 80 | + - name: Temporary Artifacts Cleanup |
| 81 | + run: rm -rf ./artifacts |
| 82 | + |
| 83 | + unit-tests: |
| 84 | + name: Unit Tests |
| 85 | + runs-on: ubuntu-latest |
| 86 | + needs: [ checkstyle, spotbugs ] |
| 87 | + steps: |
| 88 | + - name: Checkout Repository |
| 89 | + uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + fetch-depth: 0 |
| 92 | + - name: Setup Java 21 LTS |
| 93 | + uses: actions/setup-java@v4 |
| 94 | + with: |
| 95 | + java-version: 21 |
| 96 | + distribution: 'temurin' |
| 97 | + |
| 98 | + - name: Execute Unit Tests |
| 99 | + run: ./gradlew test jacocoTestReport --parallel --build-cache |
| 100 | + working-directory: ./service |
| 101 | + |
| 102 | + - name: Collect Artifacts |
| 103 | + if: always() |
| 104 | + run: | |
| 105 | + mkdir -p artifacts |
| 106 | + cp -r ./service/build/reports ./artifacts |
| 107 | +
|
| 108 | + - name: Upload Artifacts |
| 109 | + uses: actions/upload-artifact@v4 |
| 110 | + if: always() |
| 111 | + with: |
| 112 | + name: 'Unit Test Reports' |
| 113 | + path: ./artifacts/** |
| 114 | + compression-level: 9 |
| 115 | + |
| 116 | + - name: Temporary Artifacts Cleanup |
| 117 | + run: rm -rf ./artifacts |
| 118 | + |
| 119 | + integration-tests: |
| 120 | + name: Integration Tests |
| 121 | + runs-on: ubuntu-latest |
| 122 | + needs: [ checkstyle, spotbugs ] |
| 123 | + steps: |
| 124 | + - name: Checkout Repository |
| 125 | + uses: actions/checkout@v4 |
| 126 | + |
| 127 | + - name: Setup Java 21 LTS |
| 128 | + uses: actions/setup-java@v4 |
| 129 | + with: |
| 130 | + java-version: 21 |
| 131 | + distribution: 'temurin' |
| 132 | + |
| 133 | + - name: Start Docker Dependencies |
| 134 | + env: |
| 135 | + PEM111_AMQP_BROKER: "amqp://activemq:5672" |
| 136 | + PEM111_AMQP_PORT: "5672" |
| 137 | + PEM111_ITK_EXTERNAL_CONFIGURATION_URL: "http://wiremock:8080/configuration/ods-dos" |
| 138 | + LOG_LEVEL: DEBUG |
| 139 | + run: | |
| 140 | + docker network create 111network |
| 141 | + docker compose build |
| 142 | + docker compose up activemq wiremock --detach |
| 143 | + working-directory: ./docker |
| 144 | + |
| 145 | + - name: Execute Integration Tests |
| 146 | + run: ./gradlew integrationTest |
| 147 | + working-directory: ./service |
| 148 | + |
| 149 | + - name: Dump Docker Logs |
| 150 | + if: always() |
| 151 | + run: | |
| 152 | + chmod +x dump_docker_logs.sh |
| 153 | + ./dump_docker_logs.sh |
| 154 | + working-directory: ./scripts |
| 155 | + shell: bash |
| 156 | + |
| 157 | + - name: Collect Artifacts |
| 158 | + if: always() |
| 159 | + run: | |
| 160 | + mkdir -p artifacts |
| 161 | + cp -r ./service/build/reports ./artifacts |
| 162 | + cp -r ./scripts/logs ./artifacts |
| 163 | +
|
| 164 | + - name: Upload Artifacts |
| 165 | + uses: actions/upload-artifact@v4 |
| 166 | + if: always() |
| 167 | + with: |
| 168 | + name: 'Integration Test Reports & Docker Logs' |
| 169 | + path: ./artifacts/** |
| 170 | + compression-level: 9 |
| 171 | + |
| 172 | + - name: Stop Docker Dependencies |
| 173 | + if: always() |
| 174 | + run: | |
| 175 | + docker compose down --rmi=local --volumes --remove-orphans |
| 176 | + docker compose rm |
| 177 | + docker network rm 111network |
| 178 | + working-directory: ./docker |
| 179 | + |
| 180 | + - name: Temporary Artifacts Cleanup |
| 181 | + run: rm -rf ./artifacts |
| 182 | + |
| 183 | + generate-build-id: |
| 184 | + name: Generate Build ID |
| 185 | + runs-on: ubuntu-latest |
| 186 | + needs: [unit-tests, integration-tests] |
| 187 | + outputs: |
| 188 | + build-id: ${{ steps.generate.outputs.buildId }} |
| 189 | + steps: |
| 190 | + - name: Checkout Repository |
| 191 | + uses: actions/checkout@v4 |
| 192 | + |
| 193 | + - id: generate |
| 194 | + working-directory: ./scripts |
| 195 | + shell: bash |
| 196 | + run: | |
| 197 | + chmod +x ./create_build_id.sh |
| 198 | + |
| 199 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 200 | + GIT_BRANCH=PR |
| 201 | + elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/master" ]]; then |
| 202 | + GIT_BRANCH=master |
| 203 | + fi |
| 204 | + |
| 205 | + BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }}) |
| 206 | + echo "Generated the build tag: $BUILD_ID" |
| 207 | + echo "buildId=$BUILD_ID" >> $GITHUB_OUTPUT |
| 208 | +
|
| 209 | +
|
| 210 | + build-and-publish-docker-images: |
| 211 | + name: Build & Publish Docker Images |
| 212 | + runs-on: ubuntu-latest |
| 213 | + needs: [unit-tests, integration-tests, generate-build-id] |
| 214 | + permissions: |
| 215 | + id-token: write |
| 216 | + contents: read |
| 217 | + strategy: |
| 218 | + matrix: |
| 219 | + config: |
| 220 | + - directory: service |
| 221 | + repository: 111 |
| 222 | + build-context: . |
| 223 | + - directory: nginx |
| 224 | + repository: 111-nginx |
| 225 | + build-context: . |
| 226 | + |
| 227 | + if: github.actor != 'dependabot[bot]' |
| 228 | + steps: |
| 229 | + - name: Checkout Repository |
| 230 | + uses: actions/checkout@v4 |
| 231 | + |
| 232 | + - name: Configure AWS Credentials |
| 233 | + uses: aws-actions/configure-aws-credentials@v4 |
| 234 | + with: |
| 235 | + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 236 | + role-session-name: 111_github_action_build_workflow |
| 237 | + aws-region: ${{ secrets.AWS_REGION || 'eu-west-2' }} |
| 238 | + |
| 239 | + - name: Build Docker Image |
| 240 | + run: | |
| 241 | + # Create Docker Tag |
| 242 | + DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" |
| 243 | + DOCKER_TAG="$DOCKER_REGISTRY/${{ matrix.config.repository }}:${{ needs.generate-build-id.outputs.build-id }}" |
| 244 | + echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV |
| 245 | + |
| 246 | + # Build Image |
| 247 | + docker build -f ./docker/${{ matrix.config.directory }}/Dockerfile -t $DOCKER_TAG ${{ matrix.config.build-context }} |
| 248 | +
|
| 249 | + - name: Login to AWS ECR |
| 250 | + run: | |
| 251 | + DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" |
| 252 | + aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $DOCKER_REGISTRY |
| 253 | +
|
| 254 | + - name: Publish image to ECR |
| 255 | + run: docker push $DOCKER_TAG |
| 256 | + |
| 257 | + - name: Logout of AWS ECR (Clean up Credentials) |
| 258 | + if: always() |
| 259 | + run: | |
| 260 | + DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" |
| 261 | + docker logout $DOCKER_REGISTRY |
| 262 | +
|
| 263 | + comment: |
| 264 | + if: github.event_name == 'pull_request' |
| 265 | + name: "Create Build ID Comment" |
| 266 | + needs: [generate-build-id] |
| 267 | + continue-on-error: true |
| 268 | + permissions: write-all |
| 269 | + runs-on: [ ubuntu-latest ] |
| 270 | + steps: |
| 271 | + - name: Check out code |
| 272 | + uses: actions/checkout@v4 |
| 273 | + - name: Comment PR |
| 274 | + uses: thollander/actions-comment-pull-request@v3 |
| 275 | + with: |
| 276 | + message: | |
| 277 | + Images built and published to ECR using a Build Id of ${{ needs.generate-build-id.outputs.build-id }} |
| 278 | + comment_tag: images-built |
| 279 | + mode: upsert |
| 280 | + |
0 commit comments