Publish Docker Image #10
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: Publish Docker Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| force_republish: | |
| description: 'Force republish existing version (overwrite Docker tag)' | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| actions: write | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| - name: Determine Version | |
| id: determine_version | |
| run: | | |
| FORCE="${{ inputs.force_republish }}" | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| if [ "$FORCE" = "true" ]; then | |
| echo "Force republish request. Using current version v$CURRENT_VERSION without bumping." | |
| echo "VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | |
| elif git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then | |
| echo "Tag v$CURRENT_VERSION already exists. Bumping patch version..." | |
| # Bump version and push | |
| npm version patch -m "chore: bump version to %s" | |
| git push --follow-tags | |
| # Get new version | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "New version is $NEW_VERSION" | |
| echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| else | |
| echo "Tag v$CURRENT_VERSION does not exist. Using current version..." | |
| echo "VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | |
| fi | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/rack-planner:${{ env.VERSION }} | |
| ${{ secrets.DOCKER_USERNAME }}/rack-planner:latest | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| name: Release v${{ env.VERSION }} | |
| body: "Release for version ${{ env.VERSION }}" | |
| draft: false | |
| prerelease: false | |
| allowUpdates: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Trigger Deployment | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "Waiting for git propagation..." | |
| sleep 5 | |
| gh workflow run deploy.yml --ref main |