git-project-manager/.gitea/workflows/ci.yml

85 lines
2.9 KiB
YAML
Raw Normal View History

2024-12-19 20:21:35 +00:00
name: Build and Publish
on:
push:
tags: ["v*"]
env:
PACKAGE_NAME: git-project-manager
BINARY_PATH: bin
BINARY_NAME: git-project-manager
GO_MOD_PATH: gitea.libretechconsulting.com/rmcguire/git-project-manager
GO_GIT_HOST: gitea.libretechconsulting.com
2025-01-01 02:16:05 +00:00
PLATFORMS: linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
2024-12-19 20:21:35 +00:00
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
2025-01-01 01:51:04 +00:00
env:
VERSION: ${{ github.ref_name }}
2024-12-19 20:21:35 +00:00
run: make all
2025-01-01 02:16:05 +00:00
- name: Upload Binaries to Generic Registry
2024-12-19 20:21:35 +00:00
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
run: |
2025-01-01 02:16:05 +00:00
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
2024-12-19 20:21:35 +00:00
- name: Generate and Upload Package to Go Registry
env:
GOPRIVATE: gitea.libretechconsulting.com/*
API_TOKEN: ${{ secrets.API_TOKEN }} # Replace with a Gitea token stored in repository secrets
run: |
# Set up netrc for Gitea
echo "machine ${GO_GIT_HOST} login ${GITHUB_REPOSITORY_OWNER} password ${API_TOKEN}" > ~/.netrc
chmod 0600 ~/.netrc
# Package and get mod info
go mod download -x --json ${GO_MOD_PATH}@${{ github.ref_name }} | tee package.json
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 | tr -d '"' )
# Upload to Gitea go registry
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"
- 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 gitea.libretechconsulting.com/${GITHUB_REPOSITORY}@$TAG_NAME
else
echo "Error: Invalid tag format '$TAG_NAME'. Expected 'vX.X.X'."
exit 1
fi