Publish Docker Image #1
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: | |
| permissions: | |
| contents: 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: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| if 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 [skip ci]" | |
| 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: Build and Push Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| 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 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |