mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-02 22:01:05 +02:00
commit
1ecc2bdbec
1 changed files with 41 additions and 17 deletions
58
.github/workflows/docker_build.yaml
vendored
58
.github/workflows/docker_build.yaml
vendored
|
|
@ -18,13 +18,13 @@ on:
|
||||||
default: ''
|
default: ''
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write # Needed for pushing tags
|
||||||
|
packages: write # Needed for pushing docker images to GHCR
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tag_release:
|
tag_release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
# Removed env: IMAGE_TAG here, it's not used correctly across jobs
|
||||||
IMAGE_TAG: ${{ needs.tag_release.outputs.new_tag }}
|
|
||||||
outputs:
|
outputs:
|
||||||
# Define output to pass the tag to the next job
|
# Define output to pass the tag to the next job
|
||||||
new_tag: ${{ steps.tag_version.outputs.next_version }}
|
new_tag: ${{ steps.tag_version.outputs.next_version }}
|
||||||
|
|
@ -36,6 +36,8 @@ jobs:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
# Checkout the specific branch if provided, otherwise default
|
# Checkout the specific branch if provided, otherwise default
|
||||||
ref: ${{ github.event.inputs.branch }}
|
ref: ${{ github.event.inputs.branch }}
|
||||||
|
# Token needed to push tags back
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Get latest SemVer tag and calculate next version
|
- name: Get latest SemVer tag and calculate next version
|
||||||
id: tag_version
|
id: tag_version
|
||||||
|
|
@ -49,13 +51,19 @@ jobs:
|
||||||
|
|
||||||
if [ -z "$LATEST_TAG" ]; then
|
if [ -z "$LATEST_TAG" ]; then
|
||||||
echo "No previous SemVer tag found. Starting with v0.1.0"
|
echo "No previous SemVer tag found. Starting with v0.1.0"
|
||||||
NEXT_VERSION="v0.1.0"
|
# Determine initial version based on bump type (optional, v0.1.0 is often fine)
|
||||||
# Optionally adjust starting version based on bump_type, but v0.1.0 is common start
|
case "${{ github.event.inputs.bump_type }}" in
|
||||||
if [ "${{ github.event.inputs.bump_type }}" == "minor" ]; then
|
patch|minor)
|
||||||
NEXT_VERSION="v0.1.0" # Or maybe v0.1.0 ? Depends on convention
|
NEXT_VERSION="v0.1.0"
|
||||||
elif [ "${{ github.event.inputs.bump_type }}" == "major" ]; then
|
;;
|
||||||
NEXT_VERSION="v1.0.0" # Or maybe v1.0.0 ? Depends on convention
|
major)
|
||||||
fi
|
NEXT_VERSION="v1.0.0"
|
||||||
|
;;
|
||||||
|
*) # Should not happen due to 'choice' input, but good practice
|
||||||
|
echo "Invalid bump type: ${{ github.event.inputs.bump_type }}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
echo "Latest tag found: $LATEST_TAG"
|
echo "Latest tag found: $LATEST_TAG"
|
||||||
# Remove 'v' prefix for calculation
|
# Remove 'v' prefix for calculation
|
||||||
|
|
@ -94,32 +102,41 @@ jobs:
|
||||||
|
|
||||||
- name: Create and Push Tag
|
- name: Create and Push Tag
|
||||||
run: |
|
run: |
|
||||||
|
# Configure Git user identity for annotated tag (FIX)
|
||||||
|
git config --global user.name 'github-actions[bot]'
|
||||||
|
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
|
||||||
|
|
||||||
NEXT_TAG="${{ steps.tag_version.outputs.next_version }}"
|
NEXT_TAG="${{ steps.tag_version.outputs.next_version }}"
|
||||||
COMMIT_SHA=$(git rev-parse HEAD)
|
COMMIT_SHA=$(git rev-parse HEAD)
|
||||||
echo "Tagging commit $COMMIT_SHA with $NEXT_TAG"
|
echo "Tagging commit $COMMIT_SHA with $NEXT_TAG"
|
||||||
|
|
||||||
# Create an annotated tag (recommended)
|
# Create an annotated tag (recommended) - this requires user.name/email
|
||||||
git tag -a "$NEXT_TAG" -m "Release $NEXT_TAG"
|
git tag -a "$NEXT_TAG" -m "Release $NEXT_TAG"
|
||||||
|
|
||||||
# Push the tag to the remote repository
|
# Push the tag to the remote repository
|
||||||
|
echo "Pushing tag $NEXT_TAG to origin"
|
||||||
git push origin "$NEXT_TAG"
|
git push origin "$NEXT_TAG"
|
||||||
|
|
||||||
- name: Verify Tag Push
|
- name: Verify Tag Push
|
||||||
run: |
|
run: |
|
||||||
echo "Checking if tag ${{ steps.tag_version.outputs.next_version }} exists remotely..."
|
echo "Checking if tag ${{ steps.tag_version.outputs.next_version }} exists remotely..."
|
||||||
|
# Give remote a second to update
|
||||||
|
sleep 5
|
||||||
git ls-remote --tags origin | grep "refs/tags/${{ steps.tag_version.outputs.next_version }}" || (echo "Tag push verification failed!" && exit 1)
|
git ls-remote --tags origin | grep "refs/tags/${{ steps.tag_version.outputs.next_version }}" || (echo "Tag push verification failed!" && exit 1)
|
||||||
echo "Tag successfully pushed."
|
echo "Tag successfully pushed."
|
||||||
|
|
||||||
build__and_push_docker_image:
|
build_and_push_docker_image: # Renamed job slightly for clarity
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: tag_release
|
needs: tag_release # Depends on the tag being created successfully
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write # Need permission to write to GHCR
|
||||||
contents: read
|
contents: read # Need permission to read repo contents (checkout)
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
# No need to checkout specific ref here, use default branch code
|
||||||
|
# The tag is just metadata for the Docker image version
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
|
|
@ -137,12 +154,19 @@ jobs:
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ github.repository_owner }}/surfsense_backend
|
images: ghcr.io/${{ github.repository_owner }}/surfsense_backend
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=0.0.1
|
# Use the tag generated in the previous job (FIX)
|
||||||
|
type=raw,value=${{ needs.tag_release.outputs.new_tag }}
|
||||||
|
# Optionally add 'latest' tag if building from the default branch
|
||||||
|
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: ./surfsense_backend
|
context: ./surfsense_backend
|
||||||
push: true
|
push: true
|
||||||
tags: $IMAGE_TAG
|
# Use the tags generated by the metadata action (FIX)
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
# Optional: Add build cache for faster builds
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue