Skip to content

build: fix nuget search username in build workflow #19

build: fix nuget search username in build workflow

build: fix nuget search username in build workflow #19

Workflow file for this run

name: Build
on:
workflow_dispatch:
schedule:
- cron: '0 7 * * *'
push:
branches:
- master
jobs:
build:
if: contains(github.event.commits[0].message, '[skip ci]') == false &&
github.repository == 'roblox-csharp/types' &&
github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Configure Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "noreply@github.com"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Install xmlstarlet
run: sudo apt-get update && sudo apt-get install -y xmlstarlet
- name: Generate Files
run: TypeGenerator/bin/Release/net8.0/TypeGenerator -o RobloxTypes
- name: Push Generated Files
run: |
git add -A
if ! git diff-index --quiet HEAD --; then
echo "Generated files changed!"
git commit -m "feat: update generated files [skip ci]"
git push https://R-unic:${{ secrets.github_token }}@github.com/roblox-csharp/types.git HEAD:master
fi
- name: Copy Files to Deploy Branch and Publish
run: |
cd ..
git clone --depth=50 --branch=deploy https://R-unic:${{ secrets.github_token }}@github.com/roblox-csharp/types.git deploy
mkdir -p deploy/Include
rm -rf deploy/Include/*
cp -r types/RobloxTypes/* deploy/Include
cp types/RobloxTypes/Generated/PluginSecurity.cs deploy/PluginSecurity.cs
cp types/RobloxTypes/README.md deploy/README.md
cp types/RobloxTypes/RobloxTypes.csproj deploy/RobloxTypes.csproj
cd deploy
git add -A
if ! git diff-index --quiet HEAD --; then
echo "Deploy changed!"
if [ "$GITHUB_EVENT_NAME" == "push" ]; then
git commit -m "build: manual update"
else
git commit -m "build: automatic update"
fi
# set -x # Debug mode
# Extract current version from .csproj
CURRENT_VERSION=$(xmlstarlet sel -t -v "//Project/PropertyGroup/Version" ./RobloxTypes.csproj)
echo "Current version: $CURRENT_VERSION"
# Increment patch version
IFS='.' read -r -a version_parts <<< "$CURRENT_VERSION"
PATCH_VERSION=$((version_parts[2] + 1))
NEW_VERSION="${version_parts[0]}.${version_parts[1]}.$PATCH_VERSION"
echo "New version: $NEW_VERSION"
# Update version in .csproj
xmlstarlet ed -L -u "//Project/PropertyGroup/Version" -v "$NEW_VERSION" ./RobloxTypes.csproj
# Commit version change
git add ./RobloxTypes.csproj
git commit -m "build: bump version to $NEW_VERSION"
git push https://R-unic:${{ secrets.github_token }}@github.com/roblox-csharp/types.git HEAD:deploy
# Add GitHub source to NuGet
dotnet nuget add source --username roblox-csharp --password ${{ secrets.github_token }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/roblox-csharp/index.json"
# Package the project
dotnet pack --configuration Release
VERSION_EXISTS=$(dotnet nuget search roblox-csharp --source "github" | grep -c "$NEW_VERSION" || true)
echo "VERSION_EXISTS=$VERSION_EXISTS"
if [ "$VERSION_EXISTS" -eq 0 ]; then
# Find and publish the latest package
PACKAGE_PATH=$(find ./RobloxTypes/bin/Release -name "*.nupkg" -type f -print0 | xargs -0 ls -1t | head -n 1)
echo "Publishing package: $PACKAGE_PATH"
dotnet nuget push "$PACKAGE_PATH" --api-key ${{ secrets.github_token }} --source "github"
else
echo "The version is already published. Skipping publish step."
fi
fi
- name: Send Build Failure Notification
uses: rjstone/discord-webhook-notify@v1
if: failure()
with:
severity: error
details: Build Failed!
webhookUrl: ${{ secrets.WEBHOOK_URL }}