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 b2008e5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 73 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ RUN apt install -y --no-install-recommends \
python3-pytest-xdist \
python3-dbusmock \
python3-dbus

# Install doc dependencies
RUN apt install -y --no-install-recommends \
python3-sphinx-copybutton \
python3-sphinxext-opengraph \
furo \
python3-sphinx
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-2

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 }}
56 changes: 16 additions & 40 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,22 @@ concurrency:
cancel-in-progress: false

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

build:
runs-on: ubuntu-20.04
container:
image: fedora:latest
steps:
- name: Install dependencies
run: |
dnf install -y \
desktop-file-utils \
flatpak-devel \
fontconfig-devel \
fuse3 \
fuse3-devel \
gcc \
gdk-pixbuf2-devel \
geoclue2-devel \
gettext \
glib2-devel \
gnome-desktop-testing \
gtk-doc \
json-glib-devel \
libcap \
libcap-devel \
libportal-devel \
llvm \
meson \
pipewire-devel \
python3-gobject \
shared-mime-info \
systemd-devel
runs-on: ubuntu-latest
needs: build-container
permissions:
contents: write

- name: Install dependencies for doc builds
run: |
dnf install -y \
ca-certificates \
git \
python-sphinx-copybutton \
python-sphinxext-opengraph \
python3-furo \
python3-sphinx
container:
image: ${{ needs.build-container.outputs.image }}
options: ${{ needs.build-container.outputs.image_options }}

steps:
- name: Check out xdg-desktop-portal
uses: actions/checkout@v4

Expand All @@ -77,12 +52,13 @@ jobs:

# Deployment job
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') }}

steps:
- name: Deploy to GitHub Pages
id: deployment
Expand Down
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 b2008e5

Please sign in to comment.