Skip to content

Commit

Permalink
Add CI workflow for automated testing and release
Browse files Browse the repository at this point in the history
  • Loading branch information
itSubeDibesh committed Oct 15, 2024
1 parent 4921ce2 commit b256ef6
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: CI

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.16]
os: [windows-latest, macos-latest, ubuntu-latest]
arch: [amd64, arm64]
include:
- os: windows-latest
arch: amd64
- os: macos-latest
arch: amd64
- os: macos-latest
arch: arm64
- os: ubuntu-latest
arch: amd64
- os: ubuntu-latest
arch: arm64

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Install Go for ARM64 (Linux)
if: ${{ matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest' }}
run: |
sudo rm -rf /usr/local/go
curl -L https://golang.org/dl/go1.16.linux-arm64.tar.gz | sudo tar -C /usr/local -xz
echo "/usr/local/go/bin" >> $GITHUB_PATH
- name: Set environment variables
run: |
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
if [[ "${{ matrix.os }}" == 'windows-latest' ]]; then
echo "GOOS=windows" >> $GITHUB_ENV
echo "EXT=.exe" >> $GITHUB_ENV
elif [[ "${{ matrix.os }}" == 'macos-latest' ]]; then
echo "GOOS=darwin" >> $GITHUB_ENV
echo "EXT=" >> $GITHUB_ENV
else
echo "GOOS=linux" >> $GITHUB_ENV
echo "EXT=" >> $GITHUB_ENV
fi
- name: Run Tests
run: |
GOOS=${{ env.GOOS }} GOARCH=${{ env.GOARCH }} go test -v ./...
- name: Build binary
run: |
mkdir -p build
GOOS=${{ env.GOOS }} GOARCH=${{ env.GOARCH }} go build -ldflags="-s -w" -o build/cleaner-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.EXT }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: cleaner-${{ matrix.os }}-${{ matrix.arch }}
path: build/*

release:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Download artifacts
uses: actions/download-artifact@v2
with:
path: ./build

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Assets
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./build/*
asset_name: ""
tag: ${{ github.ref }}

0 comments on commit b256ef6

Please sign in to comment.