base layout and CI
This commit is contained in:
80
.gitea/workflows/build-linux.yml
Normal file
80
.gitea/workflows/build-linux.yml
Normal 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"
|
||||
Reference in New Issue
Block a user