|
| 1 | +--- |
| 2 | + |
| 3 | +name: CI |
| 4 | + |
| 5 | +on: # yamllint disable-line rule:truthy |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - 'master' |
| 9 | + tags: |
| 10 | + - 'v*.*.*' |
| 11 | + pull_request: |
| 12 | + branches: |
| 13 | + - 'master' |
| 14 | + release: |
| 15 | + types: |
| 16 | + - 'created' |
| 17 | + schedule: |
| 18 | + # Every sunday at 01:10 |
| 19 | + - cron: '10 1 * * 0' |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + name: Build |
| 24 | + runs-on: ubuntu-latest |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + postgres_version: ['14', '15'] |
| 29 | + os_version: ['alpine'] |
| 30 | + steps: |
| 31 | + - uses: e1himself/[email protected] |
| 32 | + |
| 33 | + - name: Checkout |
| 34 | + |
| 35 | + |
| 36 | + - name: Set Environment Variables |
| 37 | + env: |
| 38 | + IMAGE_NAMESPACE: wayofdev/postgres |
| 39 | + TEMPLATE: ${{ matrix.postgres_version }}-${{ matrix.os_version }} |
| 40 | + run: | |
| 41 | + export RELEASE_VERSION=${GITHUB_REF#refs/*/} |
| 42 | + echo "IMAGE_NAMESPACE=${IMAGE_NAMESPACE}" >> $GITHUB_ENV |
| 43 | + echo "TEMPLATE=${TEMPLATE}" >> $GITHUB_ENV |
| 44 | + echo "VERSION=${RELEASE_VERSION:1}" >> $GITHUB_ENV |
| 45 | +
|
| 46 | + - name: Docker Meta |
| 47 | + id: meta |
| 48 | + uses: docker/metadata-action@v3 |
| 49 | + with: |
| 50 | + images: ${{ env.IMAGE_NAMESPACE }} |
| 51 | + tags: | |
| 52 | + type=raw,event=branch,value=latest |
| 53 | + type=ref,event=pr |
| 54 | + type=semver,pattern={{version}} |
| 55 | + type=semver,pattern={{major}}.{{minor}} |
| 56 | + flavor: | |
| 57 | + latest=false |
| 58 | + prefix=${{ matrix.postgres_version }}-${{ matrix.os_version }}- |
| 59 | +
|
| 60 | + - name: Login to DockerHub |
| 61 | + if: github.event_name != 'pull_request' |
| 62 | + uses: docker/login-action@v2 |
| 63 | + with: |
| 64 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 65 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 66 | + |
| 67 | + ### For Cross Platform OSX builds uncomment these lines |
| 68 | + - name: Set up QEMU |
| 69 | + uses: docker/setup-qemu-action@v2 |
| 70 | + with: |
| 71 | + platforms: arm64 |
| 72 | + |
| 73 | + - name: Set up Docker Buildx |
| 74 | + uses: docker/setup-buildx-action@v2 |
| 75 | + with: |
| 76 | + install: true |
| 77 | + |
| 78 | + - name: Build and Export to Docker |
| 79 | + uses: docker/build-push-action@v3 |
| 80 | + with: |
| 81 | + context: ./dist/${{ env.TEMPLATE }} |
| 82 | + load: true |
| 83 | + tags: ${{ steps.meta.outputs.tags }} |
| 84 | + cache-from: type=registry,ref=${{ env.IMAGE_TAG }} |
| 85 | + cache-to: type=inline |
| 86 | + labels: ${{ steps.meta.outputs.labels }} |
| 87 | + |
| 88 | + - name: Test Docker Release Image |
| 89 | + if: success() && startsWith(github.ref, 'refs/tags/') |
| 90 | + run: | |
| 91 | + IMAGE_TAG=${{ env.IMAGE_NAMESPACE }}:${{ env.TEMPLATE }}-${{ env.VERSION }} make test |
| 92 | +
|
| 93 | + - name: Test Docker Master Image |
| 94 | + if: success() && ! startsWith(github.ref, 'refs/tags/') |
| 95 | + run: | |
| 96 | + IMAGE_TAG=${{ env.IMAGE_NAMESPACE }}:${{ env.TEMPLATE }}-latest make test |
| 97 | +
|
| 98 | + - name: Push Docker Image |
| 99 | + uses: docker/build-push-action@v3 |
| 100 | + with: |
| 101 | + context: ./dist/${{ env.TEMPLATE }} |
| 102 | + ### For Cross Platform OSX builds uncomment these lines |
| 103 | + platforms: linux/amd64,linux/arm64 |
| 104 | + push: ${{ github.event_name != 'pull_request' }} |
| 105 | + tags: ${{ steps.meta.outputs.tags }} |
| 106 | + cache-from: type=registry,ref=${{ env.IMAGE_TAG }} |
| 107 | + cache-to: type=inline |
| 108 | + |
| 109 | +... |
0 commit comments