-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build for multiple architectures (#6)
- Loading branch information
Showing
1 changed file
with
61 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,95 @@ | ||
name: Build | ||
on: [push] | ||
jobs: | ||
build: | ||
compile: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
arch: [amd64, arm64, mips] | ||
os: [darwin, linux] | ||
exclude: | ||
- arch: mips | ||
os: darwin | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
- name: Build | ||
run: go build -tags netgo,osusergo | ||
- name: Format | ||
run: test -z $(gofmt -l .) || (gofmt -d . && exit 1) | ||
- uses: actions/upload-artifact@v4 | ||
run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -tags netgo,osusergo | ||
- name: Upload binary | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: binary | ||
name: binary-${{ matrix.os }}-${{ matrix.arch }} | ||
path: mdns2mqtt | ||
if-no-files-found: error | ||
- name: Debian package | ||
if: ${{ matrix.os == 'linux' }} | ||
uses: bpicode/github-action-fpm@master | ||
with: | ||
fpm_opts: -s dir -t deb -n mdns2mqtt -a ${{ matrix.arch }} -v 0.0.0 mdns2mqtt=/usr/bin/mdns2mqtt | ||
- name: Upload .deb package | ||
uses: actions/upload-artifact@v4 | ||
if: ${{ matrix.os == 'linux' }} | ||
with: | ||
name: debian-${{ matrix.os }}-${{ matrix.arch }} | ||
path: "*.deb" | ||
if-no-files-found: error | ||
- name: Set up QEMU | ||
if: ${{ matrix.os == 'linux' }} | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
if: ${{ matrix.os == 'linux' }} | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Build and load | ||
if: ${{ matrix.os == 'linux' }} | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
outputs: type=docker,dest=/tmp/image.tar | ||
tags: invlid/mdns2mqtt:latest | ||
- uses: actions/upload-artifact@v4 | ||
platforms: ${{ matrix.os }}/${{ matrix.arch }} | ||
outputs: type=docker,dest=/tmp/image-${{ matrix.arch }}.tar | ||
tags: invlid/mdns2mqtt:latest-${{ matrix.arch }} | ||
- name: Upload Docker image | ||
if: ${{ matrix.os == 'linux' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: docker-image | ||
path: /tmp/image.tar | ||
name: docker-image-${{ matrix.arch }} | ||
path: /tmp/image-${{ matrix.arch }}.tar | ||
if-no-files-found: error | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
- name: Lint | ||
run: test -z $(gofmt -l .) || (gofmt -d . && exit 1) | ||
publish: | ||
needs: build | ||
needs: compile | ||
if: github.ref == 'refs/heads/master' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: docker-image | ||
merge-multiple: true | ||
pattern: docker-image-* | ||
path: /tmp | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USER }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Load image | ||
- name: Set up Crane | ||
uses: imjasonh/setup-crane@v0.1 | ||
- name: Log in to Docker registry | ||
run: | | ||
docker load --input /tmp/image.tar | ||
- name: Push image | ||
crane auth login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }} docker.io | ||
- name: Push images | ||
run: | | ||
docker push invlid/mdns2mqtt:latest | ||
crane push /tmp/image-amd64.tar docker.io/invlid/mdns2mqtt:latest-amd64 | ||
crane push /tmp/image-arm64.tar docker.io/invlid/mdns2mqtt:latest-arm64 | ||
crane push /tmp/image-mips.tar docker.io/invlid/mdns2mqtt:latest-mips | ||
crane index append \ | ||
-m docker.io/invlid/mdns2mqtt@$(crane digest --tarball /tmp/image-amd64.tar) \ | ||
-m docker.io/invlid/mdns2mqtt@$(crane digest --tarball /tmp/image-arm64.tar) \ | ||
-m docker.io/invlid/mdns2mqtt@$(crane digest --tarball /tmp/image-mips.tar) \ | ||
-t docker.io/invlid/mdns2mqtt:latest |