|
| 1 | +# Continuous integration, including test and integration test |
| 2 | +name: CI |
| 3 | + |
| 4 | +# Run in master and dev branches and in all pull requests to those branches |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [ master, dev ] |
| 8 | + pull_request: |
| 9 | + branches: [ master, dev ] |
| 10 | + |
| 11 | +env: |
| 12 | + DOCKER_IMAGE: radarbase/radar-output-restructure |
| 13 | + |
| 14 | +jobs: |
| 15 | + # Build and test the code |
| 16 | + build: |
| 17 | + # The type of runner that the job will run on |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 21 | + steps: |
| 22 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + |
| 25 | + - uses: actions/setup-java@v1 |
| 26 | + with: |
| 27 | + java-version: 11 |
| 28 | + |
| 29 | + - name: Gradle cache |
| 30 | + uses: actions/cache@v2 |
| 31 | + with: |
| 32 | + # Cache gradle directories |
| 33 | + path: | |
| 34 | + ~/.gradle/caches |
| 35 | + ~/.gradle/wrapper |
| 36 | + # An explicit key for restoring and saving the cache |
| 37 | + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts', 'gradle.properties') }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-gradle- |
| 40 | +
|
| 41 | + # Compile the code |
| 42 | + - name: Compile code |
| 43 | + run: ./gradlew assemble |
| 44 | + |
| 45 | + # Gradle check |
| 46 | + - name: Check |
| 47 | + run: ./gradlew check |
| 48 | + |
| 49 | + - uses: actions/upload-artifact@v2 |
| 50 | + if: always() |
| 51 | + with: |
| 52 | + name: integration-test-logs |
| 53 | + path: build/container-logs/ |
| 54 | + retention-days: 7 |
| 55 | + |
| 56 | + # Check that the docker image builds correctly |
| 57 | + docker: |
| 58 | + # The type of runner that the job will run on |
| 59 | + runs-on: ubuntu-latest |
| 60 | + |
| 61 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 62 | + steps: |
| 63 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 64 | + - uses: actions/checkout@v2 |
| 65 | + |
| 66 | + - name: Cache Docker layers |
| 67 | + uses: actions/cache@v2 |
| 68 | + with: |
| 69 | + path: /tmp/.buildx-cache |
| 70 | + key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '**/*.gradle.kts', 'gradle.properties', 'src/main/**') }} |
| 71 | + restore-keys: | |
| 72 | + ${{ runner.os }}-buildx- |
| 73 | +
|
| 74 | + # Add Docker labels and tags |
| 75 | + - name: Docker meta |
| 76 | + id: docker_meta |
| 77 | + uses: crazy-max/ghaction-docker-meta@v2 |
| 78 | + with: |
| 79 | + images: ${{ env.DOCKER_IMAGE }} |
| 80 | + |
| 81 | + - name: Login to Docker Hub |
| 82 | + uses: docker/login-action@v1 |
| 83 | + with: |
| 84 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 85 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 86 | + |
| 87 | + # Setup docker build environment |
| 88 | + - name: Set up QEMU |
| 89 | + uses: docker/setup-qemu-action@v1 |
| 90 | + |
| 91 | + - name: Set up Docker Buildx |
| 92 | + uses: docker/setup-buildx-action@v1 |
| 93 | + |
| 94 | + - name: Build |
| 95 | + uses: docker/build-push-action@v2 |
| 96 | + with: |
| 97 | + context: ./ |
| 98 | + file: ./Dockerfile |
| 99 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 100 | + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max |
| 101 | + load: true |
| 102 | + tags: ${{ steps.docker_meta.outputs.tags }} |
| 103 | + # Use runtime labels from docker_meta as well as fixed labels |
| 104 | + labels: | |
| 105 | + ${{ steps.docker_meta.outputs.labels }} |
| 106 | + maintainer=Joris Borgdorff <[email protected]> |
| 107 | + org.opencontainers.image.authors=Joris Borgdorff <[email protected]> |
| 108 | + org.opencontainers.image.vendor=RADAR-base |
| 109 | + org.opencontainers.image.licenses=Apache-2.0 |
| 110 | +
|
| 111 | + - name: Inspect image |
| 112 | + run: | |
| 113 | + docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} |
| 114 | + docker run --rm ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} --help |
| 115 | +
|
| 116 | + # If the image was pushed, we need to pull it again to inspect it |
| 117 | + - name: Push image |
| 118 | + if: ${{ github.event_name != 'pull_request' }} |
| 119 | + run: docker push ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} |
0 commit comments