mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2026-07-23 21:35:47 +00:00
150 lines
4.2 KiB
YAML
150 lines
4.2 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*'
|
|
pull_request:
|
|
|
|
concurrency: ${{ github.ref_name }}
|
|
|
|
jobs:
|
|
tests:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
make: ["lint", "unit-test", "integration-test"]
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: install go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: ${{ matrix.make }}
|
|
run: make ${{ matrix.make }}
|
|
|
|
build-binaries:
|
|
runs-on: ubuntu-latest
|
|
needs: tests
|
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- goos: linux
|
|
goarch: amd64
|
|
- goos: linux
|
|
goarch: arm64
|
|
- goos: darwin
|
|
goarch: amd64
|
|
- goos: darwin
|
|
goarch: arm64
|
|
- goos: windows
|
|
goarch: amd64
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: install go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: Set env
|
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
|
|
|
- name: Build
|
|
run: make build VERSION="$RELEASE_VERSION" GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}
|
|
|
|
- name: Package
|
|
run: |
|
|
BASE="whatismyip-$RELEASE_VERSION-${{ matrix.goos }}-${{ matrix.goarch }}"
|
|
if [ "${{ matrix.goos }}" = "windows" ]; then
|
|
cp whatismyip "${BASE}.exe"
|
|
zip "${BASE}.zip" "${BASE}.exe" LICENSE README.md
|
|
sha256sum "${BASE}.zip" > "${BASE}.zip.sha256"
|
|
else
|
|
tar zcvf "${BASE}.tar.gz" whatismyip LICENSE README.md
|
|
sha256sum "${BASE}.tar.gz" > "${BASE}.tar.gz.sha256"
|
|
fi
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v6
|
|
with:
|
|
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
path: |
|
|
whatismyip-${{ env.RELEASE_VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.*
|
|
if-no-files-found: error
|
|
|
|
publish-docker:
|
|
runs-on: ubuntu-latest
|
|
needs: tests
|
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: Set env
|
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Sign in to Docker Hub
|
|
uses: docker/login-action@v4
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
build-args: ARG_VERSION=${{ env.RELEASE_VERSION }}
|
|
tags: |
|
|
${{ secrets.DOCKERHUB_USERNAME }}/whatismyip:${{ env.RELEASE_VERSION }}
|
|
${{ secrets.DOCKERHUB_USERNAME }}/whatismyip:latest
|
|
push: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
needs: [build-binaries, publish-docker]
|
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set env
|
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v6
|
|
with:
|
|
pattern: binary-*
|
|
merge-multiple: true
|
|
|
|
- name: Generate changelog
|
|
run: |
|
|
git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:%h - %s <%an>' --no-merges > changelog.txt
|
|
|
|
- name: Release
|
|
uses: softprops/action-gh-release@v3
|
|
with:
|
|
body_path: changelog.txt
|
|
files: |
|
|
whatismyip-${{ env.RELEASE_VERSION }}-*.tar.gz
|
|
whatismyip-${{ env.RELEASE_VERSION }}-*.tar.gz.sha256
|
|
whatismyip-${{ env.RELEASE_VERSION }}-*.zip
|
|
whatismyip-${{ env.RELEASE_VERSION }}-*.zip.sha256
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|