fix(ci): use DOCKERHUB_PASSWORD for description update #131
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 and Push Docker Image | |
| on: | |
| push: | |
| branches: | |
| - 'master' | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history and tags | |
| - name: Calculate version | |
| id: version | |
| run: | | |
| # Get today's date in YYYY.MM.DD format | |
| TODAY=$(date -u +%Y.%m.%d) | |
| echo "Today's date: $TODAY" | |
| # Fetch all tags | |
| git fetch --tags | |
| # Find the highest build number for today | |
| LATEST_BUILD=$(git tag --list "${TODAY}-*" | sed "s/${TODAY}-//" | sort -n | tail -1) | |
| if [ -z "$LATEST_BUILD" ]; then | |
| # No builds today, start at 00 | |
| BUILD_NUM="00" | |
| else | |
| # Increment the build number | |
| NEXT_NUM=$((10#$LATEST_BUILD + 1)) | |
| BUILD_NUM=$(printf "%02d" $NEXT_NUM) | |
| fi | |
| VERSION="${TODAY}-${BUILD_NUM}" | |
| echo "Version: $VERSION" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Update version in files | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| # Update README.md | |
| sed -i "s/Current version: \*\*[^*]*\*\*/Current version: **${VERSION}**/" README.md | |
| # Update package.json | |
| cd client | |
| npm version "$VERSION" --no-git-tag-version --allow-same-version | |
| cd .. | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| xhenxhe/dailynotes:latest | |
| xhenxhe/dailynotes:${{ steps.version.outputs.version }} | |
| - name: Create and push git tag | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$VERSION" -m "Release $VERSION" | |
| git push origin "$VERSION" | |
| - name: Update repo description | |
| uses: peter-evans/dockerhub-description@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| repository: xhenxhe/dailynotes |