From 4020a01682cbca8207590181f6b354dce2b52151 Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Tue, 4 Nov 2025 20:37:15 -0500 Subject: [PATCH] Added release workflow. --- .gitea/workflows/release.yml | 97 ++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..116394a --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,97 @@ +name: release +on: + push: + tags: + - 'v*' # v1.2.3, v1.2.3-rc.1, etc. + +jobs: + build-and-publish-image: + name: Build & Publish Image + runs-on: [self-hosted, linux, x64, docker] # NAS or any Linux runner with Docker + env: + REGISTRY: ${{ secrets.REGISTRY_HOST }} + OWNER_REPO: ${{ github.repository }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: { dotnet-version: '9.0.x' } + + - run: dotnet restore + - run: dotnet publish JSMR/JSMR.Api/JSMR.Api.csproj -c Release -o publish + + - name: Create Dockerfile.ci + run: | + cat > Dockerfile.ci <<'EOF' + FROM mcr.microsoft.com/dotnet/aspnet:9.0 + WORKDIR /app + COPY publish/ ./ + ENV ASPNETCORE_URLS=http://+:8080 + EXPOSE 8080 + ENTRYPOINT ["dotnet", "JSMR.Api.dll"] + EOF + + - name: Normalize image name + id: names + run: | + IMAGE_LC="$(echo "${REGISTRY}/${OWNER_REPO}" | tr '[:upper:]' '[:lower:]')" + echo "image=${IMAGE_LC}" >> "$GITHUB_OUTPUT" + # tag derived from ref, e.g. refs/tags/v1.3.0 -> v1.3.0 + echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" + + - name: Docker login + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" \ + | docker login "${{ env.REGISTRY }}" \ + -u "${{ secrets.REGISTRY_USER }}" \ + --password-stdin + + - name: Build image + run: docker build -f Dockerfile.ci -t "${{ steps.names.outputs.image }}:${{ steps.names.outputs.tag }}" . + + - name: Push image + run: | + docker push "${{ steps.names.outputs.image }}:${{ steps.names.outputs.tag }}" + docker tag "${{ steps.names.outputs.image }}:${{ steps.names.outputs.tag }}" "${{ steps.names.outputs.image }}:latest" + docker push "${{ steps.names.outputs.image }}:latest" + + - uses: actions/upload-artifact@v4 + with: + name: api-publish-${{ steps.names.outputs.tag }} + path: publish + + create-gitea-release: + name: Create Gitea Release + needs: build-and-publish-image + runs-on: [self-hosted, linux, x64, docker] + steps: + - uses: actions/checkout@v4 + + # simplest notes: use tag message (annotated) and attach image refs + - name: Generate basic notes + id: notes + run: | + echo "## Release $GITHUB_REF_NAME" > REL_NOTES.md + echo "" >> REL_NOTES.md + echo "- Image: ${{ secrets.REGISTRY_HOST }}/${{ github.repository }}:${GITHUB_REF_NAME}" >> REL_NOTES.md + echo "- Latest: ${{ secrets.REGISTRY_HOST }}/${{ github.repository }}:latest" >> REL_NOTES.md + + # Gitea has a create-release action too; if not, use API curl + - name: Create Release via API + env: + GITEA_BASE: ${{ secrets.GITEA_BASE_URL }} # e.g. https://gitea.example.com + TOKEN: ${{ secrets.GITEA_TOKEN }} # personal access token w/ repo write + run: | + BODY="$(cat REL_NOTES.md)" + curl -sS -X POST "${GITEA_BASE}/api/v1/repos/${{ github.repository }}/releases" \ + -H "Authorization: token ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d @- <