eia-api-go/.gitea/workflows/ci.yml

74 lines
2.4 KiB
YAML

name: Build and Publish
on:
push:
tags: ["v*"]
env:
PACKAGE_NAME: eia-api-go
BINARY_PATH: bin
BINARY_NAME: eia-client
GO_MOD_PATH: gitea.libretechconsulting.com/50W/eia-api-go
GOPRIVATE: gitea.libretechconsulting.com/*
# DOCKER_HOST: "unix:///var/run/user/1000/docker.sock"
# DOCKER_ORG: "rmcguire"
# DOCKER_LATEST: "latest"
jobs:
build:
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 all # Build the binary
- name: Upload Client Binary to Generic Registry
env:
API_TOKEN: ${{ secrets.API_TOKEN }} # Replace with a Gitea token stored in repository secrets
run: |
if [ -f ./${BINARY_PATH}/${BINARY_NAME} ]; then
curl -X PUT \
-H "Authorization: token ${API_TOKEN}" \
--upload-file ./${BINARY_PATH}/${BINARY_NAME} \
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/${PACKAGE_NAME}/${{ github.ref_name }}/${BINARY_NAME}"
else
echo "Error: Binary ./${BINARY_PATH}/${BINARY_NAME} not found."
exit 1
fi
- name: Generate and Upload Package to Go Registry
run: |
go list --json
go mod download -x --json ${GO_MOD_PATH}@${{ github.ref_name }} 2>&1
if [[ $? -ne 0 ]]; then
echo "Failed to generage go package archive for ${GO_MOD_PATH}@${{ github.ref_name }}"
exit 1
fi
ZIPFILE=$( jq .Zip < package.json )
echo "Uploading go package ${ZIPFILE}"
curl -X PUT \
-H "Authorization: token ${API_TOKEN}" \
--upload-file ${ZIPFILE} \
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/go/upload"
publish:
runs-on: ubuntu-latest
needs: build # Ensure this stage runs only after 'build' is successful
steps:
- 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
echo GOPROXY=proxy.golang.org go list -m libretechconsulting.com/${GITHUB_REPOSITORY}@$TAG_NAME
else
echo "Error: Invalid tag format '$TAG_NAME'. Expected 'vX.X.X'."
exit 1
fi