Merge pull request #3 from pabateman/dependabot/go_modules/github.com… #47
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: Build and Release | |
on: | |
push: | |
branches: | |
- "*" | |
tags: | |
- "v*" | |
pull_request: | |
branches: | |
- "*" | |
env: | |
ARTIFACT_VERSION: ${{ github.ref_name }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
goos: [linux, darwin] | |
goarch: [amd64, arm64] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.22.4' | |
- name: Verify go.mod is sane | |
run: go mod tidy && git diff --no-patch --exit-code | |
- name: Run code lint | |
uses: golangci/golangci-lint-action@v6.0.1 | |
with: | |
args: --timeout=3m | |
- name: Install dependencies | |
run: go mod download | |
- name: Build binaries | |
run: | | |
GOOS=${{ matrix.goos }} \ | |
GOARCH=${{ matrix.goarch }} \ | |
go build \ | |
-installsuffix "static" \ | |
-ldflags " \ | |
-X main.Version=${ARTIFACT_VERSION:-"local"} \ | |
-X main.GoVersion=$(go version | cut -d " " -f 3) \ | |
-X main.Compiler=$(go env CC) \ | |
-X main.Platform=$(go env GOOS)/$(go env GOARCH) \ | |
" \ | |
-o ./ \ | |
./... | |
mkdir -p dist | |
cp dns-lookuper dist/dns-lookuper-${{ matrix.goos }}-${{ matrix.goarch }} | |
- name: Upload binaries | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dns-lookuper-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: dist | |
release: | |
needs: build | |
if: startsWith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
goos: [linux, darwin] | |
goarch: [amd64, arm64] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dns-lookuper-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: dist | |
- name: Generate Checksums | |
id: upload-checksums | |
run: | | |
cd dist | |
for file in *; do sha256sum "$file" > "$file.sha256"; done | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
draft: false | |
prerelease: false | |
files: dist/* | |
docker: | |
needs: build | |
if: startsWith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
- 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.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: dns-lookuper-linux-* | |
path: dist | |
- name: Prepare Docker context | |
run: | | |
mkdir -p docker | |
cp dist/dns-lookuper-linux-*/* docker | |
echo " | |
FROM ubuntu:oracular as intermediate | |
WORKDIR /dist | |
COPY dns-lookuper-linux-* . | |
ARG TARGETPLATFORM | |
ARG BUILDPLATFORM | |
RUN mkdir -p /target && \\ | |
cp ./dns-lookuper-\$(echo \$TARGETPLATFORM | tr '/' '-') /target/dns-lookuper | |
FROM ubuntu:oracular | |
COPY --from=intermediate /target/dns-lookuper /dns-lookuper | |
RUN chmod +x /dns-lookuper | |
ENTRYPOINT [ \"/dns-lookuper\" ] | |
" > docker/Dockerfile | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v3 | |
with: | |
context: docker | |
push: true | |
tags: | | |
pabateman/dns-lookuper:latest | |
pabateman/dns-lookuper:${{ github.ref_name }} | |
platforms: linux/amd64,linux/arm64 |