86 lines
2.7 KiB
YAML
86 lines
2.7 KiB
YAML
name: Build, Package & Release Next.js
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build & Push Docker Image
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ github.repository }}
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
repository-url: http://172.17.0.1:3000/${{ github.repository }}
|
|
ref: main
|
|
|
|
- name: Read Version from package.json
|
|
run: |
|
|
VERSION=$(jq -r '.version' package.json)
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: 172.17.0.1:3000
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- 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
|
|
with:
|
|
repository: ${{ github.repository }}
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
repository-url: http://172.17.0.1:3000/${{ github.repository }}
|
|
ref: main
|
|
|
|
- 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}" \
|
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases/tags/v$VERSION")
|
|
|
|
if [ "$HTTP_STATUS" -eq 404 ]; then
|
|
echo "Creating release v$VERSION in Gitea..."
|
|
curl -X POST \
|
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"v$VERSION\",
|
|
\"target_commitish\": \"main\",
|
|
\"name\": \"Release v$VERSION\",
|
|
\"body\": \"Automated release for version v$VERSION\",
|
|
\"draft\": false,
|
|
\"prerelease\": $PRERELEASE
|
|
}" \
|
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases"
|
|
else
|
|
echo "Release v$VERSION exists already. Skipping."
|
|
fi |