From cc9228f447bb09517d50584c31e771e7be5bd387 Mon Sep 17 00:00:00 2001 From: Ville Korhonen Date: Mon, 17 Jun 2024 17:44:46 +0300 Subject: [PATCH] Use pre-built Docker image It seems that GitHub Actions can't checkout submodules during building the containerized action. So, let's build image first using GitHub Actions, publish it, and then use it for action execution. Related: --- .github/workflows/build-and-deploy.yml | 77 ++++++++++++++++++++++++++ action.yml | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-and-deploy.yml diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..d65236d --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,77 @@ +--- +name: Build and deploy images +on: + schedule: + # rebuild every 16th day of the month at 15:24 UTC + - cron: '24 15 16 * *' + push: + branches: + - main + - feature/** + - bugfix/** + pull_request: + branches: + - '*' + +permissions: + contents: read + packages: write + actions: read + +jobs: + build-image: + name: Build image + runs-on: ubuntu-latest + env: + image: ghcr.io/seravo/phpcs + steps: + - id: refname + name: Convert git refname to valid Docker tag + run: echo "refname=$(echo "${{ github.ref_name }}" |sed 's/\//-/g')" >> $GITHUB_OUTPUT + + - id: clone-repository + uses: actions/checkout@v4 + name: Clone git repository + with: + submodules: true + + - id: docker-login + uses: Seravo/actions/docker-login@v1.4.0 + name: Login to ghcr.io + + # To speed up builds, try to use previously built image as cache source. + # However, skip this if we're running weekly scheduled build to ensure + # that we get latest APT versions at least once a week + - if: ${{ github.event_name != 'schedule' }} + name: Pull previously built image + id: docker-pull + uses: Seravo/actions/docker-pull-previous@v1.4.0 + with: + image: "${{ env.image }}" + + - id: docker-build + uses: Seravo/actions/docker-build@v1.4.0 + name: Build image + with: + image: "${{ env.image }}" + + - if: ${{ github.ref == 'refs/heads/main' }} + name: Push new image to production + id: docker-push-master + uses: Seravo/actions/docker-push@v1.4.0 + with: + image: "${{ env.image }}" + + - id: docker-tag-push-commit + name: Tag image with commit id + uses: Seravo/actions/docker-tag-and-push@v1.4.0 + with: + source: "${{ env.image }}" + target: "${{ env.image }}:${{ github.sha }}" + + - id: docker-tag-push-refname + name: Tag image with refname + uses: Seravo/actions/docker-tag-and-push@v1.4.0 + with: + source: "${{ env.image }}" + target: "${{ env.image }}:${{ steps.refname.outputs.refname }}" diff --git a/action.yml b/action.yml index d8807ed..ae42e32 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,6 @@ inputs: runs: using: "docker" - image: "Dockerfile" + image: "docker://ghcr.io/seravo/phpcs:latest" args: - --standard=${{ inputs.rules }}