ci: refactor workflow to use standard actions

This commit is contained in:
robin committed 2026-09-03 12:21:20 +00:00
1 parent 941f7aa729
commit f688952ed8
1 file changed
+51 -63
+51 -63
View File
@@ -1,4 +1,4 @@
name: Deploy Next.js via Docker name: Build, Package & Release Next.js
on: on:
push: push:
@@ -6,74 +6,62 @@ on:
- main - main
jobs: jobs:
deploy: build-and-push:
name: Build & Push Docker Image
runs-on: ubuntu-latest runs-on: ubuntu-latest
container:
image: docker:latest
steps: steps:
- name: Checkout code - name: Checkout Code
run: | uses: actions/checkout@v4
apk add --no-cache curl unzip
curl -L -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/archive/main.zip" -o repo.zip
unzip repo.zip
mv PsalmTafel/* . 2>/dev/null || mv psalmtafel/* . 2>/dev/null || mv */* . 2>/dev/null
rm repo.zip
- name: Update Docker container - name: Read Version from package.json
id: get_version
run: | run: |
echo "Building new Next.js Docker image..."
docker build -t psalmtafel-app .
echo "Stopping old container if running..."
docker stop psalmtafel-container || true
docker rm psalmtafel-container || true
echo "Starting new container..."
docker run -d \
--name psalmtafel-container \
-p 8443:3000 \
--restart always \
psalmtafel-app
- name: Create release in Gitea
run: |
apk add --no-cache jq curl
VERSION=$(jq -r '.version' package.json) VERSION=$(jq -r '.version' package.json)
echo "Current version: v$VERSION" echo "VERSION=$VERSION" >> $GITHUB_ENV
# Shell-kompatible Prüfung (funktioniert zuverlässig in Alpine/sh) - name: Log in to Gitea Container Registry
case "$VERSION" in uses: docker/login-action@v3
0.*) with:
IS_PRERELEASE="true" registry: 172.17.0.1:3000
echo "Version starts with 0. Setting prerelease to true." username: ${{ github.actor }}
;; password: ${{ secrets.GITEA_TOKEN }}
*)
IS_PRERELEASE="false"
echo "Setting prerelease to false."
;;
esac
# Prüfen, ob das Release bereits existiert - name: Build and Push Docker Image
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ uses: docker/build-push-action@v5
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ with:
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases/tags/v$VERSION") context: .
push: true
tags: |
172.17.0.1:3000/${{ github.repository }}:v${{ env.VERSION }}
172.17.0.1:3000/${{ github.repository }}:latest
if [ "$HTTP_STATUS" -eq 404 ]; then create-release:
echo "Creating new release v$VERSION..." name: Create Gitea Release
# Gitea erstellt bei diesem Call automatisch auch den Tag v$VERSION auf 'main' needs: build-and-push
curl -X POST \ runs-on: ubuntu-latest
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ steps:
-H "Content-Type: application/json" \ - name: Checkout Code
-d "{ uses: actions/checkout@v4
\"tag_name\": \"v$VERSION\",
\"target_commitish\": \"main\", - name: Read Version from package.json
\"name\": \"Release v$VERSION\", id: get_version
\"body\": \"Automated release for version v$VERSION\", run: |
\"draft\": false, VERSION=$(jq -r '.version' package.json)
\"prerelease\": $IS_PRERELEASE echo "VERSION=$VERSION" >> $GITHUB_ENV
}" \
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases" if [[ "$VERSION" == 0.* ]]; then
echo "PRERELEASE=true" >> $GITHUB_ENV
else else
echo "Release v$VERSION already exists. Skipping creation." echo "PRERELEASE=false" >> $GITHUB_ENV
fi fi
- name: Create Release in Gitea
uses: gitea/release-action@v1
with:
state: "main"
tag: "v${{ env.VERSION }}"
name: "Release v${{ env.VERSION }}"
body: "Automated release for version v${{ env.VERSION }}"
prerelease: ${{ env.PRERELEASE == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }}