Update README.md #32
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: Docker Build and Push | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to build (leave empty for automatic versioning)' | |
| required: false | |
| type: string | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=tag | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=raw,value={{date 'YYYYMMDD'}}-{{sha}},enable={{is_default_branch}} | |
| - name: Calculate version | |
| id: version | |
| run: | | |
| if [[ -n "${{ github.event.inputs.version }}" ]]; then | |
| # Use manually specified version | |
| VERSION="${{ github.event.inputs.version }}" | |
| elif [[ $GITHUB_REF == refs/tags/* ]]; then | |
| # If this is a tag, use the tag version | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| VERSION=${VERSION#v} | |
| else | |
| # Try to get the latest tag, if none exists, start from v0.0.0 | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| LATEST_TAG=${LATEST_TAG#v} | |
| # Get the commit count from the beginning of the repository | |
| # This ensures we always have a valid number even with no tags | |
| COMMITS_SINCE_TAG=$(git rev-list --count HEAD) | |
| # Split version into major and minor | |
| MAJOR=$(echo $LATEST_TAG | cut -d. -f1) | |
| MINOR=$(echo $LATEST_TAG | cut -d. -f2) | |
| # If we couldn't parse the version properly, default to 0.0 | |
| if [[ -z "$MAJOR" ]] || [[ -z "$MINOR" ]]; then | |
| MAJOR=0 | |
| MINOR=0 | |
| fi | |
| # Calculate new version | |
| VERSION="${MAJOR}.${COMMITS_SINCE_TAG}" | |
| fi | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} | |
| ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| build-args: | | |
| BUILDKIT_INLINE_CACHE=1 | |
| provenance: false | |
| sbom: false | |
| no-cache-filters: | | |
| technitium-configurator | |
| outputs: type=registry |