Skip to content

Deploy to Production #11

Deploy to Production

Deploy to Production #11

Workflow file for this run

name: Release Pipeline
on:
workflow_dispatch:
env:
APP_NAME: Place.API
SOLUTION: Place.sln
API_PROJECT: src/Place.API/Place.API.csproj
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
pull-requests: write
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install semantic-release
run: |
npm install -g semantic-release @semantic-release/git @semantic-release/changelog @semantic-release/exec conventional-changelog-angular
- name: Create Release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Running semantic-release"
npx semantic-release --debug
if [ $? -eq 0 ]; then
echo "new_release_published=true" >> $GITHUB_OUTPUT
VERSION=$(git describe --tags --abbrev=0)
echo "new_release_version=${VERSION}" >> $GITHUB_OUTPUT
else
echo "new_release_published=false" >> $GITHUB_OUTPUT
fi
build-test-publish:
needs: release
if: needs.release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
# Build and Test
- name: Restore dependencies
run: make restore SOLUTION=${{ env.SOLUTION }}
- name: Build solution
run: make build SOLUTION=${{ env.SOLUTION }}
- name: Run unit tests
run: make test-unit SOLUTION=${{ env.SOLUTION }}
- name: Run integration tests
run: make test-integration SOLUTION=${{ env.SOLUTION }}
# Publish binaries
- name: Publish x64
run: make publish RUNTIME=linux-x64 API_PROJECT=${{ env.API_PROJECT }} APP_NAME=${{ env.APP_NAME }}
env:
PUBLISH_OUTPUT: ./publish/x64
# Create release assets
- name: Create ZIP files
run: |
cd publish
zip -r ../${{ env.APP_NAME }}-linux-x64.zip x64/*
# Upload to release
- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ needs.release.outputs.new_release_version }} \
${{ env.APP_NAME }}-linux-x64.zip \
--clobber
# Docker Setup
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push Docker images
- name: Build and Push x64 Docker image
run: |
VERSION=${{ needs.release.outputs.new_release_version }}
make docker RUNTIME=linux-x64 APP_NAME=${{ env.APP_NAME }} \
DOCKER_TAG=ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}
docker tag ${{ env.APP_NAME }}-x64 ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-x64
docker push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-x64
docker push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-x64
# Create and push multi-arch manifest
- name: Create and Push Multi-arch Manifest
run: |
VERSION=${{ needs.release.outputs.new_release_version }}
# Enable experimental features for manifest
export DOCKER_CLI_EXPERIMENTAL=enabled
# Create and push version manifest
docker manifest create ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION} \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-x64
docker manifest push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}
# Create and push latest manifest
docker manifest create ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-x64
docker manifest push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest
# Optional: Cleanup
- name: Cleanup
if: always()
run: make clean SOLUTION=${{ env.SOLUTION }}