feat: added deployment
This commit is contained in:
1 parent
91ae771ca2
commit
7cba626704
9 files changed
+208
No files matched your search
@@ -0,0 +1,91 @@
|
||||
name: ci
|
||||
|
||||
# Pull requests: build, test and build the image without pushing.
|
||||
# Push to master (direct or merged PR) or a manual run on master: release.
|
||||
# GitVersion picks the next version (patch by default, "+semver: minor|major" in a commit message for more),
|
||||
# the image is pushed as <version> and latest, and the git tag v<version> is pushed so the next release counts from it.
|
||||
# Argo CD Image Updater (infrastructure repo) deploys the newest <version>; nothing is committed back.
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths-ignore: [deploy/**, '**.md']
|
||||
pull_request:
|
||||
branches: [master]
|
||||
workflow_dispatch:
|
||||
|
||||
# Releases run one at a time, so each one computes its version after the previous one pushed its tag.
|
||||
concurrency:
|
||||
group: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'release' }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
env:
|
||||
IMAGE: ghcr.io/greboh/hearth-api
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
# global.json (SDK pin, Microsoft Testing Platform runner) lives in src/
|
||||
working-directory: src
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- run: dotnet build Hearth.slnx -c Release
|
||||
- name: Run tests
|
||||
run: |
|
||||
mapfile -t projects < <(git ls-files '*Tests.csproj')
|
||||
if [ ${#projects[@]} -eq 0 ]; then
|
||||
echo "No test projects found"
|
||||
exit 0
|
||||
fi
|
||||
for project in "${projects[@]}"; do
|
||||
dotnet test "$project" -c Release
|
||||
done
|
||||
|
||||
image:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
env:
|
||||
RELEASE: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: gittools/actions/gitversion/setup@v4
|
||||
with:
|
||||
versionSpec: 6.x
|
||||
- id: gitversion
|
||||
uses: gittools/actions/gitversion/execute@v4
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
- uses: docker/login-action@v3
|
||||
if: env.RELEASE == 'true'
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: ${{ env.RELEASE == 'true' }}
|
||||
tags: |
|
||||
${{ env.IMAGE }}:${{ steps.gitversion.outputs.majorMinorPatch }}
|
||||
${{ env.IMAGE }}:latest
|
||||
cache-from: type=gha,scope=api
|
||||
cache-to: type=gha,mode=max,scope=api
|
||||
- name: Push release tag
|
||||
if: env.RELEASE == 'true'
|
||||
env:
|
||||
TAG: v${{ steps.gitversion.outputs.majorMinorPatch }}
|
||||
run: |
|
||||
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null; then
|
||||
echo "$TAG already exists"
|
||||
exit 0
|
||||
fi
|
||||
git tag "$TAG" "$GITHUB_SHA"
|
||||
git push origin "$TAG"
|
||||
Reference in new issue
Block a user