forked from nickvanw/infping
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to Github Actions and Renew Docker
- Loading branch information
1 parent
bc2e8f0
commit 93aadf8
Showing
7 changed files
with
2,589 additions
and
421 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: docker | ||
|
||
on: | ||
push: | ||
branches: ['master'] | ||
pull_request: | ||
branches: ['master'] | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
lfs: true | ||
|
||
- name: tricks | ||
run: | | ||
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | ||
echo '${{ github.ref }}' | awk -F\, '{ split($0, v, "/"); sub(/^v/, "", v[3]); print "VERSION=" v[3] }' >>${GITHUB_ENV} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
# Log in into the registry | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
# Build and push Docker image with Buildx (don't push on PR) | ||
- name: Build Docker image | ||
uses: docker/build-push-action@v5 | ||
if: ${{ github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v') }} | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile | ||
push: false | ||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | ||
|
||
# Build and push Docker image with Buildx (don't push on PR) | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile | ||
push: true | ||
tags: | | ||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | ||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64,linux/arm/v7 |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
arch: ['amd64', 'arm64'] | ||
os: ['linux', 'darwin', 'windows'] | ||
include: | ||
- os: linux | ||
arch: 'arm' | ||
goarm: '7' | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Prepare build | ||
run: | | ||
echo "GOARCH=${{ matrix.arch }}" >>${GITHUB_ENV} | ||
echo "GOOS=${{ matrix.os }}" >>${GITHUB_ENV} | ||
if [[ ! -z "${{ matrix.goarm }}" ]]; then | ||
echo "GOARM=${{ matrix.goarm }}" >>${GITHUB_ENV} | ||
fi | ||
echo "EXEC_NAME=infping-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.goarm }}" >>${GITHUB_ENV} | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Build | ||
run: | | ||
go get -v | ||
go build -o ${EXEC_NAME} -v | ||
- name: Upload to release | ||
uses: svenstaro/upload-release-action@2 | ||
with: | ||
file: '${EXEC_NAME}' |
Oops, something went wrong.