name: Docker Image Build and Push on: push: tags: [ "v*.*.*" ] jobs: build-and-push: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Get version from package.json id: versions run: | package_version=$(cat package.json | jq -r '.version') tag_version=$(echo $GITHUB_REF | cut -d '/' -f 3) # Extract tag from ref (e.g., refs/tags/v1.2.3) echo "package_version=v$package_version" >> $GITHUB_OUTPUT echo "tag_version=$tag_version" >> $GITHUB_OUTPUT - name: Check if versions match if: ${{ steps.versions.outputs.package_version != steps.versions.outputs.tag_version }} run: | echo "Error: Tag version and package.json version do not match!" exit 1 # Stop the workflow - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push image uses: docker/build-push-action@v5 with: push: true platforms: linux/amd64 tags: markusthielker/next-base:latest, markusthielker/next-base:${{ steps.versions.outputs.tag_version }}