Skip to content

Commit

Permalink
Migrate to Github Actions and Renew Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
melchor629 authored Jan 25, 2024
1 parent bc2e8f0 commit 93aadf8
Show file tree
Hide file tree
Showing 7 changed files with 2,589 additions and 421 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/docker.yaml
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
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
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 ./...
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
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}'
Loading

0 comments on commit 93aadf8

Please sign in to comment.