Skip to content

Commit

Permalink
Use pre-built Docker image
Browse files Browse the repository at this point in the history
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: <https://github.com/orgs/community/discussions/50895>
  • Loading branch information
ypcs committed Jun 17, 2024
1 parent 00d1049 commit 685808b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
with:
image: "${{ env.image }}"

- id: docker-build
uses: Seravo/actions/[email protected]
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/[email protected]
with:
image: "${{ env.image }}"

- id: docker-tag-push-commit
name: Tag image with commit id
uses: Seravo/actions/[email protected]
with:
source: "${{ env.image }}"
target: "${{ env.image }}:${{ github.sha }}"

- id: docker-tag-push-refname
name: Tag image with refname
uses: Seravo/actions/[email protected]
with:
source: "${{ env.image }}"
target: "${{ env.image }}:${{ steps.refname.outputs.refname }}"
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ inputs:

runs:
using: "docker"
image: "Dockerfile"
image: "docker://ghcr.io/seravo/phpcs:latest"
args:
- --standard=${{ inputs.rules }}

0 comments on commit 685808b

Please sign in to comment.