base layout and CI

This commit is contained in:
2026-02-11 12:42:04 -06:00
parent ca8b1fbefd
commit 2de926c26d
2 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
name: build-linux
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITEA_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build Linux executable
run: |
mkdir -p dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o dist/infra-map-linux-amd64 .
- name: PR build complete
if: github.event_name == 'pull_request'
run: echo "PR build succeeded; release creation is skipped on pull requests."
- name: Generate dev tag
if: github.event_name != 'pull_request'
id: dev_tag
run: |
tag="dev-$(date -u +%Y%m%d-%H%M%S)-${GITHUB_SHA::7}"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "tag=$tag"
- name: Create and push tag
if: github.event_name != 'pull_request'
env:
TAG: ${{ steps.dev_tag.outputs.tag }}
run: |
git config user.name "gitea-actions"
git config user.email "gitea-actions@localhost"
git tag "$TAG" "$GITHUB_SHA"
git push origin "$TAG"
- name: Create dev release and upload binary
if: github.event_name != 'pull_request'
env:
TAG: ${{ steps.dev_tag.outputs.tag }}
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
release_json="$(curl -fsS \
-X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
"${api_url}/repos/${GITHUB_REPOSITORY}/releases" \
-d "{\"tag_name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"${TAG}\",\"prerelease\":true,\"body\":\"Automated dev build for ${GITHUB_SHA}\"}")"
release_id="$(echo "$release_json" | grep -oE '"id":[[:space:]]*[0-9]+' | head -n1 | tr -dc '0-9')"
if [ -z "$release_id" ]; then
echo "failed to parse release id"
echo "$release_json"
exit 1
fi
curl -fsS \
-X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary @dist/infra-map-linux-amd64 \
"${api_url}/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=infra-map-linux-amd64"

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module inframap
go 1.22