159 lines
5.1 KiB
YAML
159 lines
5.1 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
- develop
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
|
|
jobs:
|
|
build:
|
|
name: Build and Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '8.0.x'
|
|
|
|
- name: Restore class library
|
|
run: dotnet restore classlib/classlib.csproj
|
|
|
|
- name: Restore test project
|
|
run: dotnet restore classlib.tests/classlib.tests.csproj
|
|
|
|
- name: Build class library
|
|
run: dotnet build classlib/classlib.csproj --configuration Release --no-restore
|
|
|
|
- name: Build test project
|
|
run: dotnet build classlib.tests/classlib.tests.csproj --configuration Release --no-restore
|
|
|
|
- name: Run tests
|
|
run: dotnet test classlib.tests/classlib.tests.csproj --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage"
|
|
|
|
- name: Upload test results
|
|
uses: actions/upload-artifact@v3
|
|
if: always()
|
|
with:
|
|
name: test-results
|
|
path: classlib.tests/TestResults/
|
|
retention-days: 30
|
|
|
|
package:
|
|
name: Package Module
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '8.0.x'
|
|
|
|
- name: Build Release
|
|
run: dotnet build classlib/classlib.csproj --configuration Release
|
|
|
|
- name: Create module package
|
|
run: |
|
|
mkdir -p output/ps.ipam
|
|
|
|
# Copy compiled DLL
|
|
cp classlib/bin/Release/netstandard2.1/ps.ipam.dll output/ps.ipam/
|
|
|
|
# Copy module manifest and related files
|
|
cp ps.ipam.psd1 output/ps.ipam/
|
|
cp ps.ipam.psm1 output/ps.ipam/
|
|
cp LICENSE output/ps.ipam/
|
|
cp README.md output/ps.ipam/
|
|
|
|
# Copy types directory
|
|
cp -r types output/ps.ipam/
|
|
|
|
# Copy functions directory
|
|
cp -r functions output/ps.ipam/
|
|
|
|
# Copy images directory
|
|
cp -r images output/ps.ipam/
|
|
|
|
- name: Upload module artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ps.ipam-module
|
|
path: output/ps.ipam/
|
|
retention-days: 90
|
|
|
|
release:
|
|
name: Create Release
|
|
runs-on: ubuntu-latest
|
|
needs: package
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
steps:
|
|
- name: Download module artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: ps.ipam-module
|
|
path: ps.ipam
|
|
|
|
- name: Create release archive
|
|
run: |
|
|
zip -r ps.ipam-${{ github.ref_name }}.zip ps.ipam/
|
|
tar -czvf ps.ipam-${{ github.ref_name }}.tar.gz ps.ipam/
|
|
|
|
- name: Create Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
|
run: |
|
|
# Determine if this is a prerelease (contains hyphen like v1.0.0-beta)
|
|
PRERELEASE=false
|
|
if [[ "${{ github.ref_name }}" == *-* ]]; then
|
|
PRERELEASE=true
|
|
fi
|
|
|
|
# Create the release
|
|
RELEASE_RESPONSE=$(curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"${{ github.ref_name }}\", \"name\": \"Release ${{ github.ref_name }}\", \"body\": \"Release ${{ github.ref_name }}\", \"draft\": false, \"prerelease\": ${PRERELEASE}}" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases")
|
|
|
|
echo "Release response: ${RELEASE_RESPONSE}"
|
|
|
|
# Extract release ID
|
|
RELEASE_ID=$(echo "${RELEASE_RESPONSE}" | jq -r '.id')
|
|
|
|
if [ "${RELEASE_ID}" == "null" ] || [ -z "${RELEASE_ID}" ]; then
|
|
echo "Failed to create release"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Created release with ID: ${RELEASE_ID}"
|
|
|
|
# Upload ZIP attachment
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: multipart/form-data" \
|
|
-F "attachment=@ps.ipam-${{ github.ref_name }}.zip" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets"
|
|
|
|
# Upload tar.gz attachment
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: multipart/form-data" \
|
|
-F "attachment=@ps.ipam-${{ github.ref_name }}.tar.gz" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets"
|
|
|
|
echo "Release created successfully with attachments"
|