Simplify build process (#352)

Related to #349. This only builds the docker image on push to main. For
pull requests and pushes the whole build is tested.
This commit is contained in:
Hendrik Kleinwaechter
2024-04-28 10:51:41 +02:00
committed by GitHub
parent 2f385a82b7
commit d1b0bbead1
5 changed files with 35 additions and 89 deletions

View File

@@ -1,56 +0,0 @@
name: Create and publish a Docker image
on:
workflow_call:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Figure out branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Determine docker image tag
shell: bash
id: determine_tag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "tag=${{ steps.extract_branch.outputs.branch }}" >> $GITHUB_OUTPUT
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Buildx for caching
- uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.determine_tag.outputs.tag }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -4,12 +4,37 @@ on:
push: push:
branches: branches:
- main - main
env: env:
IMAGE: ghcr.io/${{ github.repository }}:latest LATEST_IMAGE: ghcr.io/${{ github.repository }}:latest
jobs: jobs:
build-and-push-image: build-and-push-image:
uses: ./.github/workflows/docker-build-push.yml runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Buildx for caching
- uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
release-book-website: release-book-website:
needs: build-and-push-image needs: build-and-push-image

View File

@@ -1,11 +0,0 @@
name: Test building book and website
on:
pull_request:
jobs:
test-building-book-website:
uses: ./.github/workflows/test-book-website.yml
with:
docker-image: ghcr.io/${{ github.repository }}:latest

View File

@@ -1,10 +0,0 @@
name: Test building book and website with default image
on:
push:
jobs:
test-building-book-website:
uses: ./.github/workflows/test-book-website.yml
with:
docker-image: ghcr.io/${{ github.repository }}:latest

View File

@@ -1,11 +1,9 @@
name: Test book and website for given image name: Test book and website for given image
on: on: [push, pull_request]
workflow_call:
inputs: env:
docker-image: DOCKER_IMAGE: ghcr.io/${{ github.repository }}:latest
required: true
type: string
jobs: jobs:
test-book-website: test-book-website:
@@ -16,7 +14,7 @@ jobs:
- name: Print dependency versions - name: Print dependency versions
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ${{ inputs.docker-image }} image: ${{ env.DOCKER_IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -24,7 +22,7 @@ jobs:
- name: Print build variables - name: Print build variables
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ${{ inputs.docker-image }} image: ${{ env.DOCKER_IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -32,7 +30,7 @@ jobs:
- name: Test baking the release versions - name: Test baking the release versions
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ${{ inputs.docker-image }} image: ${{ env.DOCKER_IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -48,7 +46,7 @@ jobs:
- name: Test building website - name: Test building website
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ${{ inputs.docker-image }} image: ${{ env.DOCKER_IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book