Added release workflow.
This commit is contained in:
97
.gitea/workflows/release.yml
Normal file
97
.gitea/workflows/release.yml
Normal file
@@ -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 @- <<JSON
|
||||
{
|
||||
"tag_name": "${GITHUB_REF_NAME}",
|
||||
"name": "${GITHUB_REF_NAME}",
|
||||
"body": ${jq@JSON:- <<<'$BODY'},
|
||||
"draft": false,
|
||||
"prerelease": ${GITHUB_REF_NAME##*-rc*:+false}${GITHUB_REF_NAME##*-rc*:-true}
|
||||
}
|
||||
JSON
|
||||
Reference in New Issue
Block a user