1
0

release-docker.yml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. name: Release Docker Image
  2. on:
  3. release:
  4. types: [published]
  5. workflow_dispatch:
  6. jobs:
  7. build-and-push:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Checkout code
  11. uses: actions/checkout@v4
  12. with:
  13. fetch-depth: 0 # Fetch all history and tags
  14. - name: Extract tag (manual)
  15. if: github.event_name == 'workflow_dispatch'
  16. id: set_tag_manual
  17. run: |
  18. # Checkout the latest tag and set output
  19. git fetch --tags
  20. LATEST_TAG=$(git describe --tags --abbrev=0)
  21. git checkout $LATEST_TAG
  22. echo "tag=${LATEST_TAG#v}" >> $GITHUB_OUTPUT
  23. - name: Extract tag (release)
  24. if: github.event_name == 'release'
  25. id: set_tag_release
  26. run: echo "tag=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
  27. - name: Set up Docker Buildx
  28. uses: docker/setup-buildx-action@v3
  29. - name: Log in to Docker Hub
  30. uses: docker/login-action@v3
  31. with:
  32. username: ${{ secrets.DOCKERHUB_USERNAME }}
  33. password: ${{ secrets.DOCKERHUB_TOKEN }}
  34. - name: Build and push Docker image
  35. uses: docker/build-push-action@v5
  36. with:
  37. context: .
  38. file: ./Dockerfile
  39. push: true
  40. platforms: linux/amd64,linux/arm64 # Build for both amd64 and arm64
  41. # Use extracted tag without leading 'v'
  42. tags: |
  43. yhirose4dockerhub/cpp-httplib-server:latest
  44. yhirose4dockerhub/cpp-httplib-server:${{ steps.set_tag_manual.outputs.tag || steps.set_tag_release.outputs.tag }}