Fix: Add Docker login to GHCR before pushing images (fixes #153) (#154) #84
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| tags-ignore: | |
| - '**' | |
| workflow_dispatch: | |
| inputs: | |
| debug: | |
| description: 'Enable debug output' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ghcr.io/${{ github.repository }}/ci:latest | |
| credentials: | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| options: --user root -v /var/run/docker.sock:/var/run/docker.sock | |
| outputs: | |
| should_release: ${{ steps.next_version.outputs.should_release }} | |
| new_version: ${{ steps.next_version.outputs.new_version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Debug environment | |
| run: | | |
| echo "=== GitHub Context ===" | |
| echo "github.workspace: ${{ github.workspace }}" | |
| echo "github.repository: ${{ github.repository }}" | |
| echo "github.actor: ${{ github.actor }}" | |
| echo "github.ref: ${{ github.ref }}" | |
| echo "github.ref_name: ${{ github.ref_name }}" | |
| echo "" | |
| echo "=== Environment ===" | |
| echo "PWD: $(pwd)" | |
| echo "HOME: $HOME" | |
| echo "USER: $(whoami)" | |
| echo "UID: $(id -u)" | |
| echo "GID: $(id -g)" | |
| echo "" | |
| echo "=== Workspace ownership ===" | |
| ls -la $(pwd) | |
| echo "" | |
| echo "=== Git config before fix ===" | |
| git config --global --list | grep safe.directory || echo "No safe.directory configured" | |
| - name: Fix Git ownership | |
| run: git config --global --add safe.directory /__w/cli/cli | |
| - name: Quick build first | |
| run: make | |
| - name: Run make check (fmt, vet, lint, test) | |
| run: make check | |
| - name: Set up QEMU | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get latest tag | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| id: get_tag | |
| run: | | |
| git fetch --tags | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
| echo "Latest tag: $LATEST_TAG" | |
| - name: Determine next version | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| id: next_version | |
| shell: bash | |
| run: | | |
| LATEST_TAG="${{ steps.get_tag.outputs.latest_tag }}" | |
| # Extract version numbers | |
| if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then | |
| MAJOR="${BASH_REMATCH[1]}" | |
| MINOR="${BASH_REMATCH[2]}" | |
| PATCH="${BASH_REMATCH[3]}" | |
| else | |
| MAJOR=0 | |
| MINOR=0 | |
| PATCH=0 | |
| fi | |
| # Get commits since last tag (first-parent captures PR titles from merges) | |
| COMMITS=$(git log ${LATEST_TAG}..HEAD --first-parent --pretty=format:"%s") | |
| echo "=== Commits since ${LATEST_TAG} ===" | |
| echo "$COMMITS" | |
| echo "=== End commits ===" | |
| # Check for version bump indicators | |
| BREAKING=$(echo "$COMMITS" | grep -i "BREAKING CHANGE" || true) | |
| FEAT=$(echo "$COMMITS" | grep -iE "^feat(\(|:)" || true) | |
| FIX=$(echo "$COMMITS" | grep -iE "^fix(\(|:)" || true) | |
| echo "BREAKING matches: '$BREAKING'" | |
| echo "FEAT matches: '$FEAT'" | |
| echo "FIX matches: '$FIX'" | |
| # Determine version bump | |
| if [ -n "$BREAKING" ]; then | |
| # Breaking change: bump major | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| BUMP_TYPE="major" | |
| elif [ -n "$FEAT" ]; then | |
| # Feature: bump minor | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| BUMP_TYPE="minor" | |
| elif [ -n "$FIX" ]; then | |
| # Fix: bump patch | |
| PATCH=$((PATCH + 1)) | |
| BUMP_TYPE="patch" | |
| else | |
| echo "No version bump needed (no feat/fix/breaking commits)" | |
| echo "should_release=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}" | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT | |
| echo "should_release=true" >> $GITHUB_OUTPUT | |
| echo "Version bump: $LATEST_TAG → $NEW_VERSION ($BUMP_TYPE)" | |
| - name: Build for all platforms (snapshot) | |
| if: github.ref != 'refs/heads/main' || github.event_name != 'push' | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| distribution: goreleaser | |
| version: ~> v2 | |
| args: build --snapshot --clean | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - name: Create and push tag | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.next_version.outputs.should_release == 'true' | |
| run: | | |
| NEW_VERSION="${{ steps.next_version.outputs.new_version }}" | |
| BUMP_TYPE="${{ steps.next_version.outputs.bump_type }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION (${BUMP_TYPE} bump)" | |
| git push origin "$NEW_VERSION" | |
| echo "Created and pushed tag: $NEW_VERSION" | |
| - name: Run GoReleaser (release) | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.next_version.outputs.should_release == 'true' | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| distribution: goreleaser | |
| version: ~> v2 | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} | |
| CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }} | |
| - name: Release summary | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.next_version.outputs.should_release == 'true' | |
| run: | | |
| NEW_VERSION="${{ steps.next_version.outputs.new_version }}" | |
| echo "✅ Release $NEW_VERSION created successfully!" | |
| echo "🔗 https://github.com/${{ github.repository }}/releases/tag/$NEW_VERSION" |