docs: add badge #67
This file contains 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: | |
push: | |
branches: | |
- main | |
jobs: | |
release-please: | |
if: github.event_name != 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: googleapis/release-please-action@v4 | |
id: release | |
with: | |
release-type: dart | |
token: ${{ secrets.GH_TOKEN }} | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
- name: tag major and minor versions | |
if: ${{ steps.release.outputs.release_created }} | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git tag -d v${{ steps.release.outputs.major }} || true | |
git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true | |
git push origin :v${{ steps.release.outputs.major }} || true | |
git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true | |
git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}" | |
git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}" | |
git push origin v${{ steps.release.outputs.major }} | |
git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} | |
outputs: | |
release_created: ${{ steps.release.outputs.release_created }} | |
tag_name: ${{ steps.release.outputs.tag_name }} | |
push_to_registry: | |
name: Push Docker image to Docker Hub | |
needs: | |
- release-please | |
if: ${{ ! cancelled() && needs.release-please.outputs.release_created || github.event_name == 'workflow_dispatch' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-tags: true | |
fetch-depth: 200 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUBUSERNAME }} | |
password: ${{ secrets.DOCKERHUBACCESSTOKEN }} | |
- name: Get nearest tag | |
id: get-nearest-tag | |
if: ${{ github.ref != format('refs/heads/{0}', 'main') }} | |
shell: bash | |
run: |- | |
TAGS=$(git tag --list) | |
NEAREST_TAG=$(git describe --tags --abbrev=0) | |
SPECIFIC_TAG=$(git tag --points-at $(git rev-list -n 1 $NEAREST_TAG) | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+') | |
if [[ ! -z "$SPECIFIC_TAG" ]]; then | |
echo "Nearest tag is: $SPECIFIC_TAG" | |
echo "Using tag ${SPECIFIC_TAG}-edge" | |
echo "nearest_tag=${SPECIFIC_TAG}-edge" >> $GITHUB_OUTPUT | |
else | |
echo "Nearest tag not found, using 'edge' tag" | |
echo "nearest_tag=edge" >> $GITHUB_OUTPUT | |
fi | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ secrets.DOCKERHUBUSERNAME }}/leaf2mqtt | |
tags: | | |
type=raw,value=${{ needs.release-please.outputs.tag_name }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=raw,value=${{ steps.get-nearest-tag.outputs.nearest_tag }},enable=${{ github.ref != format('refs/heads/{0}', 'main') }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
build-args: | | |
APP_VERSION=${{ steps.meta.outputs.version }} | |
push: true | |
platforms: linux/amd64,linux/arm64,linux/arm/v8 | |
tags: ${{ steps.meta.outputs.tags }} |