From 728d82f2966015b2853a34ef583da6503b917893 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 14 Apr 2023 13:00:19 +0100 Subject: [PATCH] Allow testing dockerbuild changes in pull requests (#625) --- .github/workflows/build_and_test.yaml | 51 ++++++++++++++++++++++++++- .github/workflows/build_linux.yaml | 8 +++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index fc09e03..c68afbc 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -23,8 +23,56 @@ jobs: with: arch: ${{ matrix.arch }} + # This allows core contributors to test changes to the dockerbuild image within a pull request + linux_docker: + name: Linux docker + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + outputs: + docker-image: ${{ steps.docker.outputs.image }} + permissions: + contents: read + packages: write + env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}-dockerbuild-pr + steps: + - uses: actions/checkout@v3 + + - name: "Get modified files" + id: changed_files + uses: tj-actions/changed-files@79adacd43ea069e57037edc891ea8d33013bc3da # v35 + with: + files: | + dockerbuild/* + - name: Log in to the Container registry + if: steps.changed_files.outputs.any_modified == 'true' + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - id: docker + if: steps.changed_files.outputs.any_modified == 'true' + run: | + echo "image=$IMAGE:$PR" >> $GITHUB_OUTPUT + env: + IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + PR: ${{ github.event.pull_request.number }} + + - name: Build and push Docker image + if: steps.changed_files.outputs.any_modified == 'true' + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: dockerbuild + push: true + tags: ${{ steps.docker.outputs.image }} + linux: - needs: fetch + needs: + - fetch + - linux_docker name: Linux uses: ./.github/workflows/build_linux.yaml strategy: @@ -33,6 +81,7 @@ jobs: with: config: ${{ github.event.pull_request.base.ref == 'develop' && 'element.io/nightly' || 'element.io/release' }} sqlcipher: ${{ matrix.sqlcipher }} + docker-image: ${{ needs.linux_docker.outputs.docker-image }} macos: needs: fetch diff --git a/.github/workflows/build_linux.yaml b/.github/workflows/build_linux.yaml index f9285d3..c1bf446 100644 --- a/.github/workflows/build_linux.yaml +++ b/.github/workflows/build_linux.yaml @@ -20,11 +20,15 @@ on: type: boolean required: false description: "Whether to arrange artifacts in the arrangement needed for deployment, skipping unrelated ones" + docker-image: + type: string + required: false + description: "The docker image to use for the build, defaults to ghcr.io/vector-im/element-desktop-dockerbuild" jobs: build: runs-on: ubuntu-latest container: - image: ghcr.io/vector-im/element-desktop-dockerbuild:${{ github.ref_name == 'master' && 'master' || 'develop' }} + image: ${{ inputs.docker-image || format('ghcr.io/vector-im/element-desktop-dockerbuild:{0}', github.ref_name == 'master' && 'master' || 'develop') }} defaults: run: shell: bash @@ -39,7 +43,7 @@ jobs: id: cache uses: actions/cache@v3 with: - key: ${{ runner.os }}-${{ inputs.sqlcipher }}-${{ hashFiles('hakDependencies.json', 'electronVersion') }} + key: ${{ runner.os }}-${{ inputs.docker-image || github.ref_name }}-${{ inputs.sqlcipher }}-${{ hashFiles('hakDependencies.json', 'electronVersion') }} path: | ./.hak