Add CI
This commit is contained in:
85
.gitea/workflows/ci.yml
Normal file
85
.gitea/workflows/ci.yml
Normal file
@ -0,0 +1,85 @@
|
||||
name: Build and Publish
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
|
||||
env:
|
||||
PACKAGE_NAME: ambient-local-exporter
|
||||
BINARY_PATH: bin
|
||||
BINARY_NAME: ambient-local-exporter
|
||||
GO_MOD_PATH: gitea.libretechconsulting.com/rmcguire/ambient-local-exporter
|
||||
GO_GIT_HOST: gitea.libretechconsulting.com
|
||||
VER_PKG: gitea.libretechconsulting.com/rmcguire/go-app/pkg/config
|
||||
VERSION: ${{ github.ref_name }}
|
||||
PLATFORMS: linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
|
||||
DOCKER_REGISTRY: gitea.libretechconsulting.com
|
||||
DOCKER_USER: rmcguire
|
||||
DOCKER_REPO: rmcguire/ambient-local-exporter
|
||||
DOCKER_IMG: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REPO }}
|
||||
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go Environment
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.23'
|
||||
|
||||
- name: Build Binary
|
||||
run: make build
|
||||
|
||||
- name: Upload Binaries to Generic Registry
|
||||
env:
|
||||
API_TOKEN: ${{ secrets.API_TOKEN }}
|
||||
run: |
|
||||
for platform in $PLATFORMS; do
|
||||
OS=$(echo $platform | cut -d/ -f1)
|
||||
ARCH=$(echo $platform | cut -d/ -f2)
|
||||
BINARY_FILE="${BINARY_PATH}/${PACKAGE_NAME}-${OS}-${ARCH}"
|
||||
echo "Uploading $BINARY_FILE"
|
||||
if [ -f "$BINARY_FILE" ]; then
|
||||
curl -X PUT \
|
||||
-H "Authorization: token ${API_TOKEN}" \
|
||||
--upload-file "$BINARY_FILE" \
|
||||
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/${PACKAGE_NAME}/${{ github.ref_name }}/${PACKAGE_NAME}-${OS}-${ARCH}"
|
||||
else
|
||||
echo "Error: Binary $BINARY_FILE not found."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Run Go List
|
||||
env:
|
||||
TAG_NAME: ${{ github.ref_name }} # Use the pushed tag name
|
||||
run: |
|
||||
if [[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
GOPROXY=proxy.golang.org go list -m ${GO_GIT_HOST}/${GITHUB_REPOSITORY}@$TAG_NAME
|
||||
else
|
||||
echo "Error: Invalid tag format '$TAG_NAME'. Expected 'vX.X.X'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Log in to Custom Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.DOCKER_REGISTRY }}
|
||||
username: ${{ env.DOCKER_USER }}
|
||||
password: ${{ secrets.API_TOKEN }}
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ env.DOCKER_IMG }}:${{ github.ref_name }}
|
||||
build-args:
|
||||
VER_PKG: ${{ env.VER_PKG }}.version
|
||||
VERSION: ${{ github.ref_name }}
|
Reference in New Issue
Block a user