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

77 lines
2.8 KiB
YAML
Raw Normal View History

2024-12-16 14:44:21 +00:00
name: Build and Publish
on:
push:
tags: ["v*"]
env:
PACKAGE_NAME: eia-api-go
2024-12-16 19:32:53 +00:00
BINARY_PATH: bin
2024-12-16 14:44:21 +00:00
BINARY_NAME: eia-client
2024-12-17 21:02:58 +00:00
GO_MOD_PATH: gitea.libretechconsulting.com/rmcguire/eia-api-go
2024-12-16 21:46:19 +00:00
GO_GIT_HOST: gitea.libretechconsulting.com
2024-12-16 14:44:21 +00:00
jobs:
2024-12-17 21:30:53 +00:00
release:
2024-12-16 14:44:21 +00:00
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
2024-12-16 20:51:32 +00:00
- name: Upload Client Binary to Generic Registry
2024-12-16 14:44:21 +00:00
env:
2024-12-16 19:32:53 +00:00
API_TOKEN: ${{ secrets.API_TOKEN }} # Replace with a Gitea token stored in repository secrets
2024-12-16 14:44:21 +00:00
run: |
2024-12-17 21:02:58 +00:00
echo "Pushing ./$BINARY_PATH/$BINARY_NAME to ${GITHUB_SERVER_URL} packages for ${GITHUB_REPOSITORY_OWNER} as ${PACKAGE_NAME}@${{ github.ref_name }}"
2024-12-16 19:34:51 +00:00
if [ -f ./${BINARY_PATH}/${BINARY_NAME} ]; then
2024-12-16 20:21:45 +00:00
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}"
2024-12-16 14:44:21 +00:00
else
2024-12-16 19:34:51 +00:00
echo "Error: Binary ./${BINARY_PATH}/${BINARY_NAME} not found."
2024-12-16 14:44:21 +00:00
exit 1
fi
2024-12-16 20:51:32 +00:00
- name: Generate and Upload Package to Go Registry
2024-12-16 21:40:46 +00:00
env:
GOPRIVATE: gitea.libretechconsulting.com/*
2024-12-16 21:46:19 +00:00
API_TOKEN: ${{ secrets.API_TOKEN }} # Replace with a Gitea token stored in repository secrets
2024-12-16 20:51:32 +00:00
run: |
2024-12-16 21:48:11 +00:00
# Set up netrc for Gitea
2024-12-16 21:46:19 +00:00
echo "machine ${GO_GIT_HOST} login ${GITHUB_REPOSITORY_OWNER} password ${API_TOKEN}" > ~/.netrc
2024-12-16 21:40:46 +00:00
chmod 0600 ~/.netrc
2024-12-16 21:48:11 +00:00
# Package and get mod info
go mod download -x --json ${GO_MOD_PATH}@${{ github.ref_name }} | tee package.json
2024-12-16 20:55:53 +00:00
if [[ $? -ne 0 ]]; then
2024-12-16 20:51:32 +00:00
echo "Failed to generage go package archive for ${GO_MOD_PATH}@${{ github.ref_name }}"
exit 1
fi
2024-12-16 21:51:09 +00:00
ZIPFILE=$( jq .Zip < package.json | tr -d '"' )
2024-12-16 21:48:11 +00:00
# Upload to Gitea go registry
2024-12-16 20:55:53 +00:00
echo "Uploading go package ${ZIPFILE}"
2024-12-16 20:51:32 +00:00
curl -X PUT \
-H "Authorization: token ${API_TOKEN}" \
--upload-file ${ZIPFILE} \
"${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/go/upload"
2024-12-16 14:44:21 +00:00
- 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
2024-12-17 21:25:31 +00:00
GOPROXY=proxy.golang.org go list -m gitea.libretechconsulting.com/${GITHUB_REPOSITORY}@$TAG_NAME
2024-12-16 14:44:21 +00:00
else
echo "Error: Invalid tag format '$TAG_NAME'. Expected 'vX.X.X'."
exit 1
fi