Merge pull request 'ci: refactor workflow to use standard actions' (#43) from chore into main
Reviewed-on: Schanbro/PsalmTafel#43
This commit was merged in pull request #43.
This commit is contained in:
commit
11cd39aced
1 file changed
+45
-48
@@ -1,4 +1,4 @@
|
|||||||
name: Deploy Next.js via Docker
|
name: Build, Package & Release Next.js
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -6,62 +6,59 @@ 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
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Read Version from package.json
|
||||||
run: |
|
run: |
|
||||||
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
|
|
||||||
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
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
172.17.0.1:3000/${{ github.repository }}:v${{ env.VERSION }}
|
||||||
|
172.17.0.1:3000/${{ github.repository }}:latest
|
||||||
|
|
||||||
|
create-release:
|
||||||
|
name: Create Gitea Release
|
||||||
|
needs: build-and-push
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Create Release via Gitea API
|
||||||
|
run: |
|
||||||
|
VERSION=$(jq -r '.version' package.json)
|
||||||
|
|
||||||
|
if [[ "$VERSION" == 0.* ]]; then
|
||||||
|
PRERELEASE="true"
|
||||||
|
else
|
||||||
|
PRERELEASE="false"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prüfen, ob der Release bereits existiert
|
||||||
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases/tags/v$VERSION")
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases/tags/v$VERSION")
|
||||||
|
|
||||||
if [ "$HTTP_STATUS" -eq 404 ]; then
|
if [ "$HTTP_STATUS" -eq 404 ]; then
|
||||||
echo "Creating new release v$VERSION..."
|
echo "Creating release v$VERSION in Gitea..."
|
||||||
# Gitea erstellt bei diesem Call automatisch auch den Tag v$VERSION auf 'main'
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
@@ -71,9 +68,9 @@ jobs:
|
|||||||
\"name\": \"Release v$VERSION\",
|
\"name\": \"Release v$VERSION\",
|
||||||
\"body\": \"Automated release for version v$VERSION\",
|
\"body\": \"Automated release for version v$VERSION\",
|
||||||
\"draft\": false,
|
\"draft\": false,
|
||||||
\"prerelease\": $IS_PRERELEASE
|
\"prerelease\": $PRERELEASE
|
||||||
}" \
|
}" \
|
||||||
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases"
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases"
|
||||||
else
|
else
|
||||||
echo "Release v$VERSION already exists. Skipping creation."
|
echo "Release v$VERSION exists already. Skipping."
|
||||||
fi
|
fi
|
||||||
Reference in new issue
Block a user