ambient-local-exporter/.gitea/workflows/ci.yml
Ryan D McGuire eecaf2a82e
All checks were successful
Build and Publish / release (push) Successful in 2m44s
Add latest tag
2025-01-05 11:44:48 -05:00

88 lines
2.8 KiB
YAML

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
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@v3
- 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@v6
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMG }}:${{ github.ref_name }}
${{ env.DOCKER_IMG }}:latest
build-args: |
VER_PKG=${{ env.VER_PKG }}
VERSION=${{ github.ref_name }}