Compare commits
3 Commits
v1.0.0
..
production
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cdcdd2d29 | |||
| d832e748ec | |||
| 7e80226bf2 |
+5
-40
@@ -1,11 +1,12 @@
|
|||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
|
# Everyday checks. Runs on the working branch and on pull requests into it.
|
||||||
|
# Releasing is a separate workflow driven by the production branch.
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [dev]
|
||||||
tags: ["v*"]
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [dev, production]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -20,7 +21,7 @@ jobs:
|
|||||||
- name: Restore
|
- name: Restore
|
||||||
run: dotnet restore
|
run: dotnet restore
|
||||||
|
|
||||||
# Directory.Build.props turns warnings into errors, so this also gates style.
|
# Directory.Build.props turns warnings into errors, so this gates style too.
|
||||||
- name: Build
|
- name: Build
|
||||||
run: dotnet build --configuration Release --no-restore
|
run: dotnet build --configuration Release --no-restore
|
||||||
|
|
||||||
@@ -32,39 +33,3 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: nupkg
|
name: nupkg
|
||||||
path: artifacts/*
|
path: artifacts/*
|
||||||
|
|
||||||
publish:
|
|
||||||
# Tag pushes only: v1.2.3 publishes version 1.2.3 to nuget.org.
|
|
||||||
needs: build
|
|
||||||
if: startsWith(gitea.ref, 'refs/tags/v')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: actions/setup-dotnet@v4
|
|
||||||
with:
|
|
||||||
dotnet-version: "10.0.x"
|
|
||||||
|
|
||||||
- name: Derive version from tag
|
|
||||||
id: version
|
|
||||||
run: echo "value=${GITEA_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
|
|
||||||
env:
|
|
||||||
GITEA_REF: ${{ gitea.ref }}
|
|
||||||
|
|
||||||
- name: Pack
|
|
||||||
run: >
|
|
||||||
dotnet pack src/CertifiEd.Client/CertifiEd.Client.csproj
|
|
||||||
--configuration Release
|
|
||||||
-p:Version=${{ steps.version.outputs.value }}
|
|
||||||
--output artifacts
|
|
||||||
|
|
||||||
# NUGET_API_KEY must be added as a repository secret. Without it the step
|
|
||||||
# fails loudly rather than silently shipping nothing.
|
|
||||||
- name: Push to nuget.org
|
|
||||||
run: >
|
|
||||||
dotnet nuget push "artifacts/*.nupkg"
|
|
||||||
--source https://api.nuget.org/v3/index.json
|
|
||||||
--api-key "$NUGET_API_KEY"
|
|
||||||
--skip-duplicate
|
|
||||||
env:
|
|
||||||
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
|
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
# Merging (or pushing) into production releases whatever version the files
|
||||||
|
# declare: <Version> in src/CertifiEd.Client/CertifiEd.Client.csproj is the
|
||||||
|
# single source of truth. The workflow tags it, publishes the package to
|
||||||
|
# nuget.org and creates the Gitea release.
|
||||||
|
#
|
||||||
|
# To ship: bump <Version> on dev, merge dev -> production.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [production]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: "10.0.x"
|
||||||
|
|
||||||
|
- name: Read version from the project file
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
VERSION=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/CertifiEd.Client/CertifiEd.Client.csproj | head -1)
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
echo "::error::<Version> not found in src/CertifiEd.Client/CertifiEd.Client.csproj"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "value=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Releasing version $VERSION"
|
||||||
|
|
||||||
|
# A published NuGet version can never be replaced, so refuse to re-run an
|
||||||
|
# already released version instead of silently doing nothing.
|
||||||
|
# Checks the tag itself: a tag can exist without a release object (e.g. it
|
||||||
|
# was pushed by hand), and that still means the version is spoken for.
|
||||||
|
- name: Refuse to release an existing version
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG="v${{ steps.version.outputs.value }}"
|
||||||
|
CODE=$(curl -s -o /dev/null -w '%{http_code}' \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/tags/$TAG")
|
||||||
|
if [ "$CODE" = "200" ]; then
|
||||||
|
echo "::error::$TAG already exists — version ${{ steps.version.outputs.value }} is already released. Bump <Version> in src/CertifiEd.Client/CertifiEd.Client.csproj on dev, then merge into production again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: dotnet build --configuration Release
|
||||||
|
|
||||||
|
- name: Pack
|
||||||
|
run: >
|
||||||
|
dotnet pack src/CertifiEd.Client/CertifiEd.Client.csproj
|
||||||
|
--configuration Release --no-build --output artifacts
|
||||||
|
|
||||||
|
# No --skip-duplicate: a duplicate must fail loudly, not look successful.
|
||||||
|
- name: Publish to nuget.org
|
||||||
|
env:
|
||||||
|
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${NUGET_API_KEY:-}" ]; then
|
||||||
|
echo "::error::NUGET_API_KEY secret is not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
dotnet nuget push artifacts/*.nupkg \
|
||||||
|
--source https://api.nuget.org/v3/index.json \
|
||||||
|
--api-key "$NUGET_API_KEY"
|
||||||
|
|
||||||
|
# Tag and release only after the package is actually on nuget.org, so the
|
||||||
|
# tag always corresponds to something published.
|
||||||
|
- name: Tag and create the release
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
VERSION="${{ steps.version.outputs.value }}"
|
||||||
|
TAG="v$VERSION"
|
||||||
|
BODY="CertifiEd.Client $VERSION\n\nnuget: https://www.nuget.org/packages/CertifiEd.Client/$VERSION"
|
||||||
|
curl -sf -X POST \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\":\"$TAG\",\"target_commitish\":\"$GITHUB_SHA\",\"name\":\"$TAG\",\"body\":\"$BODY\"}" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" > /dev/null
|
||||||
|
echo "Released $TAG"
|
||||||
|
|
||||||
|
- name: Upload package artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: nupkg
|
||||||
|
path: artifacts/*
|
||||||
+32
-10
@@ -1,5 +1,12 @@
|
|||||||
# Разработка и релиз
|
# Разработка и релиз
|
||||||
|
|
||||||
|
## Ветки
|
||||||
|
|
||||||
|
| Ветка | Назначение |
|
||||||
|
|---|---|
|
||||||
|
| `dev` | Основная ветка разработки. Сюда идут все изменения и pull request'ы. CI собирает и пакует, но ничего не публикует. |
|
||||||
|
| `production` | Релизная ветка. Мерж сюда = выпуск версии. |
|
||||||
|
|
||||||
## Сборка
|
## Сборка
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -11,22 +18,37 @@ dotnet pack src/CertifiEd.Client/CertifiEd.Client.csproj -c Release -o artifacts
|
|||||||
|
|
||||||
## Релиз
|
## Релиз
|
||||||
|
|
||||||
Версия пакета берётся из тега:
|
Версия берётся **из файлов** — единственный источник правды — `<Version>` в
|
||||||
|
`src/CertifiEd.Client/CertifiEd.Client.csproj`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1. Обновить <Version> в src/CertifiEd.Client/CertifiEd.Client.csproj
|
# 1. на dev: поднять версию
|
||||||
# 2. Закоммитить и поставить тег
|
# <Version>1.0.1</Version>
|
||||||
git tag v1.0.1
|
git commit -am "chore: bump version to 1.0.1"
|
||||||
git push origin main --tags
|
git push origin dev
|
||||||
|
|
||||||
|
# 2. влить dev в production — это и есть релиз
|
||||||
|
git checkout production
|
||||||
|
git merge --no-ff dev
|
||||||
|
git push origin production
|
||||||
```
|
```
|
||||||
|
|
||||||
CI (`.gitea/workflows/ci.yml`) на теге `v*` собирает пакет с версией из тега и публикует его на nuget.org.
|
Дальше `.gitea/workflows/release.yml` сам:
|
||||||
|
|
||||||
### Что нужно один раз настроить
|
1. читает версию из csproj;
|
||||||
|
2. **отказывается** публиковать, если тег `vX.Y.Z` уже существует (опубликованную версию в NuGet заменить нельзя — нужно поднять версию);
|
||||||
|
3. собирает и пакует;
|
||||||
|
4. публикует пакет на nuget.org (дубликат падает с ошибкой, а не «молча успешно»);
|
||||||
|
5. только после успешной публикации создаёт тег `vX.Y.Z` и Gitea-release.
|
||||||
|
|
||||||
- В настройках репозитория → Actions → Secrets добавить **`NUGET_API_KEY`** — ключ nuget.org с правом публикации пакета `CertifiEd.Client`.
|
Порядок намеренный: тег появляется лишь тогда, когда пакет реально опубликован.
|
||||||
- Убедиться, что к репозиторию подключён Actions-раннер (Settings → Actions → Runners). Без раннера workflow не запустится.
|
|
||||||
|
### Что настроено один раз
|
||||||
|
|
||||||
|
- Секрет **`NUGET_API_KEY`** — ключ nuget.org с правом публикации `CertifiEd.Client`.
|
||||||
|
- Actions-раннер с лейблом `ubuntu-latest`.
|
||||||
|
- `GITEA_TOKEN` выдаётся Actions автоматически — используется для тега и релиза.
|
||||||
|
|
||||||
## Совместимость
|
## Совместимость
|
||||||
|
|
||||||
Публичный API следует semver: ломающие изменения — только в мажорной версии. Формат токена лицензии и протокол активации описаны в документации платформы CertifiEd.
|
Публичный API следует semver: ломающие изменения — только в мажорной версии.
|
||||||
|
|||||||
Reference in New Issue
Block a user