diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..7f4e4ff --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,114 @@ +name: 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] + env: + RELEASE_CIBLE: ${{ needs.set-release-target.outputs.release_cible }} + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + BINARI: ${{ matrix.binaries }} + 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/${{ matrix.binaries }}_${{ matrix.goos }}_${{ matrix.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: ${{ matrix.binaries }}-${{ env.RELEASE_CIBLE }}-${{ matrix.goos }}-${{ matrix.goarch }} + path: dist/${{ matrix.binaries }}_${{ matrix.goos }}_${{ matrix.goarch }} + prerelease: + runs-on: docker + needs: [set-release-target, build] + env: + TOKEN: ${{ secrets.RELEASE }} + TAG: ${{ needs.set-release-target.outputs.release_cible }} + 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 @- <