Skip to content

Commit

Permalink
Update actions to build container for ghcr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Feb 16, 2024
1 parent be23752 commit c64351f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
53 changes: 41 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
name: "build"
name: Build Docker Container

on: ["pull_request", "push"]
on:
workflow_dispatch:
push:
paths-ignore:
- '.gitignore'
- 'LICENSE'
- 'README.md'

env:
DOCKER_OWNER: ${{ github.repository_owner }}
DOCKER_CONTAINER: bibliothek
DOCKER_TAG: ${{ github.ref_name }}

jobs:
build:
runs-on: "ubuntu-latest"
runs-on: ubuntu-latest

steps:
- name: "checkout repository"
uses: "actions/checkout@v3"
- name: "setup java"
uses: "actions/setup-java@v3"
with:
distribution: "zulu"
java-version: "17"
- name: "build"
run: "./gradlew build"
- name: Checkout repository
uses: actions/checkout@v3

- name: Fix Docker environment variables
run: |
# Make lowercase
echo "DOCKER_OWNER=$(echo $DOCKER_OWNER | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
echo "DOCKER_CONTAINER=$(echo $DOCKER_CONTAINER | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
echo "DOCKER_TAG=$(echo $DOCKER_TAG | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
# Replace / with _
echo "DOCKER_TAG=$(echo $DOCKER_TAG | sed -e 's/\//_/g')" >> $GITHUB_ENV
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag $DOCKER_CONTAINER:$DOCKER_TAG
[[ "${{ github.ref }}" == "refs/heads/master" ]] && docker tag $DOCKER_CONTAINER:$DOCKER_TAG ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:latest
docker tag $DOCKER_CONTAINER:$DOCKER_TAG ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:$DOCKER_TAG
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push to GHCR
run: |
[[ "${{ github.ref }}" == "refs/heads/master" ]] && docker push ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:latest
docker push ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:$DOCKER_TAG
27 changes: 27 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build Pull Request

on:
workflow_dispatch:
pull_request:
paths-ignore:
- '.gitignore'
- 'LICENSE'
- 'README.md'

jobs:
build:
runs-on: "ubuntu-latest"
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin

- name: Checkout repository
uses: actions/checkout@v3

- name: Build bibliothek
uses: gradle/gradle-build-action@v2
with:
arguments: build

0 comments on commit c64351f

Please sign in to comment.