diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index 68c1c56..d3be3cf 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -9,25 +9,35 @@ on: - main jobs: - build-and-publish: - name: Build and Publish + build-and-validate: + name: Build and Validate runs-on: ubuntu + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build Docker Image + run: | + docker build -t threejs-test:test . + + - name: Validate Image + run: | + docker run --rm -d --name test-container -p 8080:80 threejs-test:test + sleep 2 + curl -f http://localhost:8080 || exit 1 + docker stop test-container + + publish: + name: Publish to Registry + runs-on: ubuntu + needs: build-and-validate + if: github.event_name == 'push' || gitea.event_name == 'push' steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for tags - - name: Check Docker availability - run: | - set -e - docker --version - docker info - - - name: Setup Docker Buildx - run: | - docker buildx create --use || true - - name: Login to Registry run: | echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login git.jusemon.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin @@ -35,13 +45,6 @@ jobs: - name: Determine Version id: version run: | - # Get branch name (works for both GitHub and Forgejo) - BRANCH_NAME="${GITHUB_REF#refs/heads/}" - BRANCH_NAME="${BRANCH_NAME#refs/remotes/origin/}" - if [[ -z "$BRANCH_NAME" ]]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) - fi - # Get latest version tag LATEST_TAG=$(git describe --tags --match 'v*.*.*' --abbrev=0 2>/dev/null || echo "v0.0.0") LATEST_VERSION="${LATEST_TAG#v}" @@ -52,61 +55,18 @@ jobs: MINOR=${MINOR:-0} PATCH=${PATCH:-0} - # Determine version bump based on branch prefix - if [[ "$BRANCH_NAME" == release/* ]]; then - # Release branch: use the version from branch name or bump minor - VERSION_FROM_BRANCH=$(echo "$BRANCH_NAME" | sed -n 's|release/\(.*\)|\1|p') - if [[ -n "$VERSION_FROM_BRANCH" && "$VERSION_FROM_BRANCH" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - NEW_VERSION="$VERSION_FROM_BRANCH" - else - MINOR=$((MINOR + 1)) - PATCH=0 - NEW_VERSION="$MAJOR.$MINOR.$PATCH" - fi - elif [[ "$BRANCH_NAME" == feature/* ]]; then - # Feature branch: bump minor version - MINOR=$((MINOR + 1)) - PATCH=0 - NEW_VERSION="$MAJOR.$MINOR.$PATCH" - elif [[ "$BRANCH_NAME" == bugfix/* ]] || [[ "$BRANCH_NAME" == hotfix/* ]]; then - # Bugfix/Hotfix: bump patch version - PATCH=$((PATCH + 1)) - NEW_VERSION="$MAJOR.$MINOR.$PATCH" - elif [[ "$BRANCH_NAME" == main ]]; then - # Main branch: increment patch version from latest tag, or start at 0.1.0 if no tags exist - if [[ "$LATEST_TAG" == "v0.0.0" ]]; then - # First version - NEW_VERSION="0.1.0" - else - # Increment patch version for each merge to main - PATCH=$((PATCH + 1)) - NEW_VERSION="$MAJOR.$MINOR.$PATCH" - fi + # Increment patch version for each merge to main, or start at 0.1.0 if no tags exist + if [[ "$LATEST_TAG" == "v0.0.0" ]]; then + # First version + NEW_VERSION="0.1.0" else - # Default: bump patch + # Increment patch version for each merge to main PATCH=$((PATCH + 1)) NEW_VERSION="$MAJOR.$MINOR.$PATCH" fi - # For PRs, use a pre-release version - EVENT_NAME="${{ github.event_name }}" - if [[ -z "$EVENT_NAME" ]]; then - EVENT_NAME="${{ gitea.event_name }}" - fi - - if [[ "$EVENT_NAME" == "pull_request" ]]; then - PR_NUMBER="${{ github.event.pull_request.number }}" - if [[ -z "$PR_NUMBER" ]]; then - PR_NUMBER="${{ gitea.event.pull_request.number }}" - fi - if [[ -n "$PR_NUMBER" ]]; then - NEW_VERSION="${NEW_VERSION}-pr${PR_NUMBER}" - fi - fi - echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT - echo "Branch: $BRANCH_NAME" echo "Latest tag: $LATEST_TAG" echo "New version: $NEW_VERSION" @@ -116,15 +76,7 @@ jobs: docker build -t "$IMAGE_NAME" . echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV - - name: Validate Image - run: | - docker run --rm -d --name test-container -p 8080:80 "$IMAGE_NAME" - sleep 2 - curl -f http://localhost:8080 || exit 1 - docker stop test-container - - name: Push Docker Image - if: (github.event_name == 'push' || gitea.event_name == 'push') && (github.ref == 'refs/heads/main' || gitea.ref == 'refs/heads/main') run: | IMAGE_NAME="git.jusemon.com/jusemon/threejs-test:${{ steps.version.outputs.version }}" docker push "$IMAGE_NAME" @@ -134,7 +86,6 @@ jobs: docker push "git.jusemon.com/jusemon/threejs-test:latest" - name: Create Git Tag - if: (github.event_name == 'push' || gitea.event_name == 'push') && (github.ref == 'refs/heads/main' || gitea.ref == 'refs/heads/main') run: | git config user.name "forgejo-actions" git config user.email "forgejo-actions@forgejo.io"