Skip to content

ci(pipeline): integrate semantic-release with build pipeline #3

ci(pipeline): integrate semantic-release with build pipeline

ci(pipeline): integrate semantic-release with build pipeline #3

Workflow file for this run

name: Release Pipeline
on:
push:
branches: [main, beta, alpha]
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
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install semantic-release
run: |
npm install -g semantic-release
npm install -g @semantic-release/git
npm install -g @semantic-release/changelog
npm install -g @semantic-release/exec
npm install -g conventional-changelog-angular
- name: Create Release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
build-and-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'
# Build and Test
- name: Restore dependencies
run: dotnet restore ${{ env.SOLUTION }}
- name: Build solution
run: dotnet build ${{ env.SOLUTION }} --configuration Release --no-restore
- name: Run unit tests
run: dotnet test ${{ env.SOLUTION }} --filter Category=Unit --no-build
- name: Run integration tests
run: dotnet test ${{ env.SOLUTION }} --filter Category=Integration --no-build
# Publish binaries
- name: Publish x64
run: |
dotnet publish ${{ env.API_PROJECT }} \
-c Release \
-r linux-musl-x64 \
--self-contained true \
-p:PublishSingleFile=true \
-o ./publish/x64
- name: Publish arm64
run: |
dotnet publish ${{ env.API_PROJECT }} \
-c Release \
-r linux-musl-arm64 \
--self-contained true \
-p:PublishSingleFile=true \
-o ./publish/arm64
# Create release assets
- name: Create ZIP files
run: |
cd publish
zip -r ../${{ env.APP_NAME }}-linux-x64.zip x64/*
zip -r ../${{ env.APP_NAME }}-linux-arm64.zip arm64/*
# Upload to release
- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.release.outputs.new_release_version }}
gh release upload $VERSION \
${{ env.APP_NAME }}-linux-x64.zip \
${{ env.APP_NAME }}-linux-arm64.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 Docker Images
env:
VERSION: ${{ needs.release.outputs.new_release_version }}
run: |
# Build and push x64
docker buildx build \
--platform linux/amd64 \
--tag ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-x64 \
--tag ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-x64 \
--push \
.
# Build and push arm64
docker buildx build \
--platform linux/arm64 \
--tag ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-arm64 \
--tag ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-arm64 \
--push \
.
# Create and push multi-arch manifest
- name: Create and Push Multi-arch Manifest
env:
VERSION: ${{ needs.release.outputs.new_release_version }}
run: |
# Create and push version manifest
docker buildx imagetools create -t ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION} \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-x64 \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-arm64
# Create and push latest manifest
docker buildx imagetools create -t ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-x64 \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-arm64