update ci #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Code Check and Release | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
# Set global defaults, including the working directory | |
defaults: | |
run: | |
working-directory: ./src # Default working directory for all jobs and steps | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Set up .NET Core using the repository-level DOTNET_VERSION environment variable | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ vars.DOTNET_VERSION }} # Using repository-level environment variable | |
# Restore dependencies | |
- name: Restore dependencies | |
run: dotnet restore | |
# Build the solution | |
- name: Build solution | |
run: dotnet build --no-restore | |
# Run unit tests | |
- name: Test | |
run: dotnet test --no-build --verbosity normal | |
bump-version: | |
runs-on: ubuntu-latest | |
if: ${{ startsWith(github.event.head_commit.message, 'release v') }} | |
needs: [ build ] | |
# override working directory for this job | |
defaults: | |
run: | |
working-directory: ./ | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 # Ensures that we have access to the full commit history | |
- name: Extract Version and Description | |
id: extract_version_description | |
run: | | |
FULL_MESSAGE="${{ github.event.head_commit.message }}" | |
SUMMARY=$(echo "$FULL_MESSAGE" | head -n 1) | |
DESCRIPTION=$(echo "$FULL_MESSAGE" | tail -n +3) | |
if [[ $SUMMARY =~ ^release\ v([0-9]+\.[0-9]+\.[0-9]+) ]]; then | |
VERSION="${BASH_REMATCH[1]}" | |
else | |
echo "Commit message does not match the pattern 'release vx.x.x'" | |
exit 1 | |
fi | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
printf "DESCRIPTION<<EOF\n%s\nEOF\n" "$DESCRIPTION" >> $GITHUB_ENV | |
echo "Bumping version to $VERSION" | |
- name: Run Version Bump Script | |
run: | | |
echo "Current directory: $(pwd)" | |
chmod +x ./bump_version.sh | |
./bump_version.sh "$VERSION" | |
- name: Configure Git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Check for Changes | |
id: check_changes | |
run: | | |
# Check if there are any changes to commit | |
if [[ -n "$(git status --porcelain)" ]]; then | |
echo "changes=true" >> $GITHUB_ENV | |
else | |
echo "changes=false" >> $GITHUB_ENV | |
fi | |
- name: Commit and Push Changes | |
id: commit_version_bump # Capture this step ID to get the commit SHA | |
if: env.changes == 'true' | |
run: | | |
# Commit the changes with the specified message | |
git add . | |
git commit -m "Bump to v$VERSION" | |
# Push changes back to main | |
git push origin main | |
env: | |
VERSION: ${{ env.VERSION }} | |
# Set up .NET Core using the repository-level DOTNET_VERSION environment variable | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: | | |
${{ vars.DOTNET_VERSION }} | |
3.1.x | |
2.1.x | |
# Restore dependencies | |
- name: Restore dependencies | |
working-directory: ./src # Override the default working directory | |
run: dotnet restore | |
# Build the solution | |
- name: Build solution | |
working-directory: ./src # Override the default working directory | |
run: dotnet build --no-restore --configuration Release | |
# Copy src/Nino/bin/Release/netstandard2.1/Nino.Core.dll and src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll | |
# to Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime, replacing the existing DLLs | |
- name: Copy DLLs | |
run: | | |
cp ./src/Nino/bin/Release/netstandard2.1/Nino.Core.dll ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime | |
cp ./src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime | |
# Commit the changes (only the 2 dlls) | |
- name: Commit Changes | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime/Nino.Core.dll ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime/Nino.Generator.dll | |
git commit -m "Bump Unity Package DLLs to v$VERSION" | |
git push origin main | |
- name: Get Commit SHA | |
run: echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
- name: Create GitHub Release | |
id: create_release # Capture the release ID for uploading assets | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: "v${{ env.VERSION }}" # Release tag, like "v1.2.3" | |
commitish: "${{ env.COMMIT_SHA }}" # Ensures the release points to the bump commit | |
release_name: "v${{ env.VERSION }}" # Title of the release, same as the tag | |
body: "${{ env.DESCRIPTION }}" # Release notes from commit message | |
draft: false # Make the release public immediately | |
prerelease: false # Mark it as a stable release | |
# Set up .NET Core using the repository-level DOTNET_VERSION environment variable | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ vars.DOTNET_VERSION }} # Using repository-level environment variable | |
# Restore dependencies | |
- name: Restore dependencies | |
working-directory: ./src # Override the default working directory | |
run: dotnet restore | |
# Build the solution | |
- name: Build solution | |
working-directory: ./src # Override the default working directory | |
run: dotnet build --configuration Release /p:OutputPath=../artifacts | |
# Push NuGet packages | |
- name: Push NuGet Packages | |
working-directory: ./src # Override the default working directory | |
run: | | |
echo "Current directory: $(pwd)" | |
for package in ./artifacts/*.nupkg; do | |
dotnet nuget push "$package" --api-key ${{ secrets.MYTOKEN }} --source https://api.nuget.org/v3/index.json | |
done | |
benchmark: | |
needs: [ bump-version ] | |
uses: JasonXuDeveloper/Nino/.github/workflows/report.yml@main |