Skip to content

Commit

Permalink
ci(pipeline): integrate semantic-release with build pipeline
Browse files Browse the repository at this point in the history
- Split pipeline into release and build jobs
- Replace make commands with direct dotnet commands
- Fix dependency caching issues
- Improve Docker multi-arch build process
- Add conditional build based on semantic-release output

BREAKING CHANGE: Pipeline structure has been completely reorganized
  • Loading branch information
GenjiruSUchiwa committed Nov 24, 2024
1 parent 49c606d commit 5048288
Showing 1 changed file with 87 additions and 69 deletions.
156 changes: 87 additions & 69 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Release Pipeline for publishing
name: Release Pipeline

on:
push:
branches: [main, beta, alpha]
workflow_dispatch:

env:
Expand All @@ -10,53 +11,91 @@ env:
API_PROJECT: src/Place.API/Place.API.csproj

jobs:
build-test-publish:
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

- uses: actions/setup-dotnet@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
dotnet-version: '9.0.x'
cache: true
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

- name: Cache NuGet packages
uses: actions/cache@v4
- uses: actions/setup-dotnet@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets') }}
restore-keys: |
${{ runner.os }}-nuget-
dotnet-version: '9.0.x'

# Build and Test
- name: Restore dependencies
run: make restore SOLUTION=${{ env.SOLUTION }}
run: dotnet restore ${{ env.SOLUTION }}

- name: Build solution
run: make build SOLUTION=${{ env.SOLUTION }}
run: dotnet build ${{ env.SOLUTION }} --configuration Release --no-restore

- name: Run unit tests
run: make test-unit SOLUTION=${{ env.SOLUTION }}
run: dotnet test ${{ env.SOLUTION }} --filter Category=Unit --no-build

- name: Run integration tests
run: make test-integration SOLUTION=${{ env.SOLUTION }}
run: dotnet test ${{ env.SOLUTION }} --filter Category=Integration --no-build

# Publish binaries
- name: Publish x64
run: make publish RUNTIME=linux-musl-x64 API_PROJECT=${{ env.API_PROJECT }} APP_NAME=${{ env.APP_NAME }}
env:
PUBLISH_OUTPUT: ./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: make publish RUNTIME=linux-musl-arm64 API_PROJECT=${{ env.API_PROJECT }} APP_NAME=${{ env.APP_NAME }}
env:
PUBLISH_OUTPUT: ./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
Expand All @@ -70,7 +109,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.event.release.tag_name }} \
VERSION=${{ needs.release.outputs.new_release_version }}
gh release upload $VERSION \
${{ env.APP_NAME }}-linux-x64.zip \
${{ env.APP_NAME }}-linux-arm64.zip \
--clobber
Expand All @@ -87,59 +127,37 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push Docker images
- name: Build x64 Docker image
run: |
VERSION=${GITHUB_REF#refs/tags/}
make docker RUNTIME=linux-musl-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
- name: Build arm64 Docker image
- name: Build and Push Docker Images
env:
VERSION: ${{ needs.release.outputs.new_release_version }}
run: |
VERSION=${GITHUB_REF#refs/tags/}
make docker RUNTIME=linux-musl-arm64 APP_NAME=${{ env.APP_NAME }} \
DOCKER_TAG=ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}
docker tag ${{ env.APP_NAME }}-arm64 ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-arm64
docker push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-arm64
docker push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-arm64
# 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
- name: Create and Push Multi-arch Manifest
env:
VERSION: ${{ needs.release.outputs.new_release_version }}
run: |
VERSION=${GITHUB_REF#refs/tags/}
# 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} \
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
docker manifest annotate ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION} \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-x64 --arch amd64
docker manifest annotate ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION} \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:${VERSION}-arm64 --arch arm64
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 \
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
docker manifest annotate ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-x64 --arch amd64
docker manifest annotate ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest \
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-arm64 --arch arm64
docker manifest push ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest
# Optional: Cleanup
- name: Cleanup
if: always()
run: make clean SOLUTION=${{ env.SOLUTION }}
ghcr.io/${{ github.repository }}/${{ env.APP_NAME }}:latest-arm64

0 comments on commit 5048288

Please sign in to comment.