Skip to content

Commit

Permalink
reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Oct 8, 2024
1 parent dcced83 commit 6a99880
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 33 deletions.
33 changes: 2 additions & 31 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,14 @@ name: Build and Test
on: [push, pull_request]

env:
IMAGE_TAG: 20240908-1
TESTS_TIMEOUT: 10 # in minutes

jobs:
build-container:
name: Create build container
runs-on: ubuntu-latest
uses: ./.github/workflows/container.yml
permissions:
packages: write

outputs:
image: ${{ steps.check.outputs.image }}

steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Check if image already exists on GHCR
id: check
run: |
image=ghcr.io/${{ github.repository_owner }}/xdg-desktop-portal-build:${{ env.IMAGE_TAG }}
echo "exists=$(docker manifest inspect $image >/dev/null && echo 'true' || echo 'false')" \
>> "$GITHUB_OUTPUT"
echo "image=$image" >> "$GITHUB_OUTPUT"
- name: Build and push
if: ${{ steps.check.outputs.exists == 'false' }}
uses: docker/build-push-action@v5
with:
push: true
file: .github/workflows/Containerfile
tags: ghcr.io/${{ github.repository_owner }}/xdg-desktop-portal-build:${{ env.IMAGE_TAG }}

build-and-test:
name: Build and Test
runs-on: ubuntu-latest
Expand All @@ -56,7 +27,7 @@ jobs:
CC: ${{ matrix.compiler }}
TEST_IN_CI: 1
G_MESSAGES_DEBUG: all
options: --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined --privileged
options: ${{ needs.build-container.outputs.image_options }}

steps:
- name: Configure environment
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Create build container

env:
IMAGE_TAG: 20240908-1

on:
workflow_call:
outputs:
image:
description: "The build image"
value: ${{ jobs.build-container.outputs.image }}
image_options:
description: "The options to use with the image"
value: --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined --privileged

jobs:
build-container:
name: Create build container
runs-on: ubuntu-latest

outputs:
image: ${{ steps.check.outputs.image }}

steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Check if image already exists on GHCR
id: check
run: |
image=ghcr.io/${{ github.repository_owner }}/xdg-desktop-portal-build:${{ env.IMAGE_TAG }}
echo "exists=$(docker manifest inspect $image >/dev/null && echo 'true' || echo 'false')" \
>> "$GITHUB_OUTPUT"
echo "image=$image" >> "$GITHUB_OUTPUT"
- name: Build and push
if: ${{ steps.check.outputs.exists == 'false' }}
uses: docker/build-push-action@v5
with:
push: true
file: .github/workflows/Containerfile
tags: ghcr.io/${{ github.repository_owner }}/xdg-desktop-portal-build:${{ env.IMAGE_TAG }}
13 changes: 11 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ on:
default: true

jobs:
build-container:
uses: ./.github/workflows/container.yml
permissions:
packages: write

release:
name: Build and publish a release
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/xdg-desktop-portal-build:latest
needs: build-container
permissions:
contents: write

container:
image: ${{ needs.build-container.outputs.image }}
options: ${{ needs.build-container.outputs.image_options }}

steps:
- name: Configure git user
run: |
Expand Down

0 comments on commit 6a99880

Please sign in to comment.