|
| 1 | +--- |
| 2 | +name: "build images" |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + workflow_dispatch: |
| 9 | + pull_request: |
| 10 | + schedule: |
| 11 | + - cron: '0 16 * * 0' # Every Sunday at 4PM |
| 12 | + |
| 13 | +env: |
| 14 | + DOCKERHUB_ORG: ${{ secrets.DOCKERHUB_ORG }} |
| 15 | + DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} |
| 16 | + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: "Build: ${{ matrix.version }}" |
| 21 | + runs-on: ubuntu-20.04 |
| 22 | + |
| 23 | + strategy: |
| 24 | + fail-fast: false # Don't cancel other jobs if one fails |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - version: "7.4" |
| 28 | + - version: "8.0" |
| 29 | + - version: "8.1" |
| 30 | + env: |
| 31 | + VERSION: ${{ matrix.version }} |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Dump GitHub context |
| 35 | + env: |
| 36 | + GITHUB_CONTEXT: ${{ toJSON(github) }} |
| 37 | + run: echo "$GITHUB_CONTEXT" |
| 38 | + |
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@v2 |
| 41 | + |
| 42 | + - name: Prepare Tags |
| 43 | + id: prep |
| 44 | + run: | |
| 45 | + DOCKERHUB_IMAGE=${DOCKERHUB_ORG}/${GITHUB_REPOSITORY#*/} |
| 46 | + GITHUB_IMAGE=${{ github.repository_owner }}/${GITHUB_REPOSITORY#*/} |
| 47 | + VERSION=php${{ matrix.version }} |
| 48 | +
|
| 49 | + TAGS="ghcr.io/${GITHUB_IMAGE}:${VERSION}" |
| 50 | + # Only push to Dockerhub if secrets are set. |
| 51 | + if [ ! -z "${DOCKERHUB_ORG}" ]; then |
| 52 | + TAGS="$TAGS,${DOCKERHUB_IMAGE}:${VERSION}" |
| 53 | + fi |
| 54 | +
|
| 55 | + # Set output parameters. |
| 56 | + echo ::set-output name=tags::${TAGS} |
| 57 | +
|
| 58 | + - name: Set up QEMU |
| 59 | + uses: docker/setup-qemu-action@v1 |
| 60 | + with: |
| 61 | + platforms: all |
| 62 | + |
| 63 | + - name: Set up Docker Buildx |
| 64 | + id: buildx |
| 65 | + uses: docker/setup-buildx-action@v1 |
| 66 | + |
| 67 | + - name: Login to DockerHub |
| 68 | + if: ${{ github.event_name != 'pull_request' && env.DOCKERHUB_ORG != '' }} |
| 69 | + uses: docker/login-action@v1 |
| 70 | + with: |
| 71 | + username: ${{ secrets.DOCKERHUB_USER }} |
| 72 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: Login to GitHub Container Registry |
| 75 | + if: ${{ github.event_name != 'pull_request' }} |
| 76 | + uses: docker/login-action@v1 |
| 77 | + with: |
| 78 | + registry: ghcr.io |
| 79 | + username: ${{ github.repository_owner }} |
| 80 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + |
| 82 | + - name: Build |
| 83 | + uses: docker/build-push-action@v2 |
| 84 | + with: |
| 85 | + builder: ${{ steps.buildx.outputs.name }} |
| 86 | + context: ./src |
| 87 | + file: ./src/Dockerfile |
| 88 | + build-args: CLI_VERSION=php${{ matrix.version }} |
| 89 | + platforms: linux/amd64,linux/arm64 |
| 90 | + push: ${{ github.event_name != 'pull_request' }} |
| 91 | + tags: ${{ steps.prep.outputs.tags }} |
0 commit comments