|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + merge_group: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - develop |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + |
| 12 | +jobs: |
| 13 | + Build: |
| 14 | + name: Build and Test on ${{ matrix.python }} and ${{ matrix.os }} |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + os: ['macos-latest', 'ubuntu-latest'] |
| 19 | + python: ['pypy3.9', 'pypy3.10', '3.9', '3.10', '3.11'] |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - name: Set up Python ${{ matrix.python }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python }} |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + id: install-deps |
| 30 | + run: | |
| 31 | + pip3 install -r requirements.txt |
| 32 | +
|
| 33 | + - name: Write version vars |
| 34 | + id: version-vars |
| 35 | + run: | |
| 36 | + BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` |
| 37 | + BRANCH=${GITHUB_REF_NAME#v} |
| 38 | + APP_VERSION=$(cat config.json | grep version| head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g') |
| 39 | + echo Version: $APP_VERSION |
| 40 | + echo "VERSION=$APP_VERSION" >> $GITHUB_ENV |
| 41 | + echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV |
| 42 | + echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV |
| 43 | +
|
| 44 | + Container: |
| 45 | + name: Build Container Image |
| 46 | + runs-on: ubuntu-latest |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + - name: Build image |
| 50 | + id: build-image |
| 51 | + uses: redhat-actions/buildah-build@v2 |
| 52 | + with: |
| 53 | + image: cloudtooling/data-anonymizer |
| 54 | + tags: 'latest next ${{env.APP_VERSION}} ${{env.APP_VERSION}}_rc' |
| 55 | + containerfiles: | |
| 56 | + ./Dockerfile |
| 57 | + build-args: | |
| 58 | + BUILD_DATE=${{env.BUILD_DATE}} |
| 59 | + APP_VERSION=${{env.APP_VERSION}} |
| 60 | +
|
| 61 | + - name: Push To Docker Hub |
| 62 | + id: push-to-dockerhub-preview |
| 63 | + uses: redhat-actions/push-to-registry@v2 |
| 64 | + with: |
| 65 | + image: ${{ steps.build-image.outputs.image }} |
| 66 | + tags: 'next ${{env.APP_VERSION}}_rc' |
| 67 | + registry: registry.hub.docker.com |
| 68 | + username: ${{ secrets.DOCKER_HUB_USER}} |
| 69 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 70 | + if: github.ref == 'refs/heads/develop' |
| 71 | + |
| 72 | + - name: Push To Docker Hub |
| 73 | + id: push-to-dockerhub-tagged |
| 74 | + uses: redhat-actions/push-to-registry@v2 |
| 75 | + with: |
| 76 | + image: ${{ steps.build-image.outputs.image }} |
| 77 | + tags: 'latest ${{env.APP_VERSION}}' |
| 78 | + registry: registry.hub.docker.com |
| 79 | + username: ${{ secrets.DOCKER_HUB_USER}} |
| 80 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 81 | + if: github.ref_type == 'tag' || github.tag != '' |
| 82 | + |
| 83 | + Build-results: |
| 84 | + name: Build results |
| 85 | + if: ${{ always() }} |
| 86 | + runs-on: ubuntu-latest |
| 87 | + needs: |
| 88 | + - Build |
| 89 | + - Container |
| 90 | + steps: |
| 91 | + - run: exit 1 |
| 92 | + # see https://stackoverflow.com/a/67532120/4907315 |
| 93 | + if: >- |
| 94 | + ${{ |
| 95 | + contains(needs.*.result, 'failure') |
| 96 | + || contains(needs.*.result, 'cancelled') |
| 97 | + || contains(needs.*.result, 'skipped') |
| 98 | + }} |
0 commit comments