start: add ci

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2025-12-14 22:14:19 +01:00
commit fb7f44a31a
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
4 changed files with 210 additions and 0 deletions

View file

@ -0,0 +1,43 @@
on:
workflow_call:
inputs:
tag:
required: true
type: string
goos:
required: true
type: string
goarch:
required: true
type: string
binari:
required: true
type: string
jobs:
build:
runs-on: docker
env:
RELEASE_CIBLE: ${{ inputs.tag }}
GOOS: ${{ inputs.goos }}
GOARCH: ${{ inputs.goarch }}
BINARI: ${{ inputs.binari }}
CGO_ENABLED: 0
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Build du projet
run: |
echo "Building for ${BINARI}/${GOOS}/${GOARCH} (release: ${RELEASE_CIBLE})"
go env GOOS GOARCH
mkdir -p dist/
go build -o dist/${BINARI}_${GOOS}_${GOARCH} ./cmd/${BINARI}
echo "artifact pour ${RELEASE_CIBLE} ${BINARI} ${GOOS} ${GOARCH}" > dist/${BINARI}-${GOOS}-${GOARCH}.txt
ls -l ./dist
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARI }}-${{ env.RELEASE_CIBLE }}-${{ env.GOOS }}-${{ env.GOARCH }}
path: dist/${{ env.BINARI }}_${{ env.GOOS }}_${{ env.GOARCH }}

View file

@ -0,0 +1,55 @@
name: Pre Release Workflow
on:
push:
tags:
- '*'
branches:
- main
pull_request:
types: [closed]
branches:
- main
jobs:
set-release-target:
runs-on: docker
outputs:
release_cible: ${{ steps.setvar.outputs.release_cible }}
steps:
- name: Déterminer la release cible
id: setvar
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG="${GITHUB_REF#refs/tags/}"
echo "release_cible=$TAG" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "release_cible=latest" >> $GITHUB_OUTPUT
else
echo "release_cible=unknown" >> $GITHUB_OUTPUT
fi
- name: Afficher la variable
run: echo "Release cible = ${{ steps.setvar.outputs.release_cible }}"
build:
runs-on: docker
needs: [set-release-target]
strategy:
matrix:
goos: [linux]
goarch: [amd64]
binaries: [db, metadata]
uses: ./.forgejo/workflows/build.yml
with:
tag: ${{ needs.set-release-target.outputs.release_cible }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
binari: ${{ matrix.binaries }}
secrets: inherit
prerelease:
runs-on: docker
needs: [set-release-target, build]
uses: ./.forgejo/workflows/release.yml
with:
tag: ${{ needs.set-release-target.outputs.release_cible }}
secrets: inherit

View file

@ -0,0 +1,56 @@
on:
workflow_call:
inputs:
tag:
required: true
type: string
jobs:
release:
runs-on: docker
env:
TOKEN: ${{ secrets.RELEASE }}
TAG: ${{ inputs.tag }}
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v3
with:
path: dist/
- name: Publier tous les binaires
run: ls -lR dist/
- name: Install jq
run: |
apt-get update
apt-get install -y jq
- name: Create prerelease
run: |
curl -X POST \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
"https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases" \
-d @- <<EOF
{
"tag_name": "$TAG",
"name": "$TAG",
"body": "Prerelease automatique générée par la CI",
"draft": false,
"prerelease": true
}
EOF
- name: Upload asset
run: |
RELEASE_ID=$(curl -s \
-H "Authorization: token ${TOKEN}" \
https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases/tags/${TAG} \
| jq -r .id)
echo ${RELEASE_ID}
ls dist | while read tmp
do
FILE=$(ls "./dist/${tmp}")
echo ${FILE}
curl -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary @dist/${tmp}/${FILE} \
"https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=${FILE}"
done