|
| 1 | +name: note-c CI Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + check_dockerfile_changed: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + changed: ${{ steps.filter.outputs.changed }} |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v3 |
| 18 | + |
| 19 | + # TODO: This is a 3rd party GitHub action from some dude. Ideally, we'd |
| 20 | + # use something more "official". |
| 21 | + - name: Check if Dockerfile changed |
| 22 | + uses: dorny/paths-filter@v2 |
| 23 | + id: filter |
| 24 | + with: |
| 25 | + base: 'master' |
| 26 | + filters: | |
| 27 | + changed: |
| 28 | + - 'Dockerfile' |
| 29 | +
|
| 30 | + build_ci_docker_image: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + needs: [check_dockerfile_changed] |
| 33 | + if: ${{ needs.check_dockerfile_changed.outputs.changed == 'true' }} |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@v3 |
| 38 | + |
| 39 | + - name: Login to GitHub Container Registry |
| 40 | + uses: docker/login-action@v2 |
| 41 | + with: |
| 42 | + registry: ghcr.io |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v2 |
| 48 | + |
| 49 | + - name: Rebuild image |
| 50 | + uses: docker/build-push-action@v4 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + load: true |
| 54 | + tags: ghcr.io/blues/note_c_ci:latest |
| 55 | + outputs: type=docker,dest=/tmp/note_c_ci_image.tar |
| 56 | + |
| 57 | + - name: Upload image artifact |
| 58 | + uses: actions/upload-artifact@v3 |
| 59 | + with: |
| 60 | + name: note_c_ci_image |
| 61 | + path: /tmp/note_c_ci_image.tar |
| 62 | + |
| 63 | + run_doxygen: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + if: ${{ always() }} |
| 66 | + needs: [build_ci_docker_image] |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Checkout code |
| 70 | + uses: actions/checkout@v3 |
| 71 | + |
| 72 | + - name: Load CI Docker image |
| 73 | + # Only load the Docker image artifact if build_ci_docker_image actually |
| 74 | + # ran (e.g. it wasn't skipped and was successful). |
| 75 | + if: ${{ needs.build_ci_docker_image.result == 'success' }} |
| 76 | + uses: ./.github/actions/load-ci-image |
| 77 | + |
| 78 | + - name: Run doxygen |
| 79 | + run: | |
| 80 | + docker run --rm --volume $(pwd):/note-c/ --workdir /note-c/ --entrypoint ./scripts/run_doxygen.sh ghcr.io/blues/note_c_ci:latest |
| 81 | +
|
| 82 | + run_unit_tests: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + if: ${{ always() }} |
| 85 | + needs: [build_ci_docker_image] |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout code |
| 89 | + uses: actions/checkout@v3 |
| 90 | + |
| 91 | + - name: Load CI Docker image |
| 92 | + if: ${{ needs.build_ci_docker_image.result == 'success' }} |
| 93 | + uses: ./.github/actions/load-ci-image |
| 94 | + |
| 95 | + - name: Run tests |
| 96 | + run: | |
| 97 | + docker run --rm --volume $(pwd):/note-c/ --workdir /note-c/ --entrypoint ./scripts/run_unit_tests.sh ghcr.io/blues/note_c_ci:latest --coverage --mem-check |
| 98 | +
|
| 99 | + - name: Adjust lcov source file paths for Coveralls |
| 100 | + run: sudo sed -i 's/\/note-c\///g' ./build/test/coverage/lcov.info |
| 101 | + |
| 102 | + - name: Publish test coverage |
| 103 | + uses: coverallsapp/github-action@master |
| 104 | + with: |
| 105 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + path-to-lcov: ./build/test/coverage/lcov.info |
| 107 | + |
| 108 | + run_astyle: |
| 109 | + runs-on: ubuntu-latest |
| 110 | + if: ${{ always() }} |
| 111 | + needs: [build_ci_docker_image] |
| 112 | + |
| 113 | + steps: |
| 114 | + - name: Checkout Code |
| 115 | + uses: actions/checkout@v3 |
| 116 | + |
| 117 | + - name: Load CI Docker image |
| 118 | + if: ${{ needs.build_ci_docker_image.result == 'success' }} |
| 119 | + uses: ./.github/actions/load-ci-image |
| 120 | + |
| 121 | + - name: Run astyle |
| 122 | + run: | |
| 123 | + docker run --rm --volume $(pwd):/note-c/ --workdir /note-c/ --entrypoint ./scripts/run_astyle.sh ghcr.io/blues/note_c_ci:latest |
| 124 | +
|
| 125 | + publish_ci_image: |
| 126 | + runs-on: ubuntu-latest |
| 127 | + # Make sure unit tests unit tests passed before publishing. |
| 128 | + needs: [build_ci_docker_image, run_unit_tests] |
| 129 | + # Only publish the image if this is a push event and the Docker image was rebuilt |
| 130 | + if: ${{ github.event_name == 'push' && needs.build_ci_docker_image.result == 'success' }} |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Login to GitHub Container Registry |
| 134 | + uses: docker/login-action@v2 |
| 135 | + with: |
| 136 | + registry: ghcr.io |
| 137 | + username: ${{ github.actor }} |
| 138 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + |
| 140 | + - name: Set up Docker Buildx |
| 141 | + uses: docker/setup-buildx-action@v2 |
| 142 | + |
| 143 | + - name: Push image to registry |
| 144 | + uses: docker/build-push-action@v4 |
| 145 | + with: |
| 146 | + push: true |
| 147 | + tags: ghcr.io/blues/note_c_ci:latest |
0 commit comments