diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..8de6999 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,44 @@ +name: CD +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0.x + + - name: Add RobloxCS GitHub packages source to NuGet + run: dotnet nuget add source --store-password-in-clear-text -u roblox-csharp -p ${{ secrets.GITHUB_TOKEN }} -n rbxcs "https://nuget.pkg.github.com/roblox-csharp/index.json" + + - name: Extract version from .csproj + id: extract_version + run: | + VERSION=$(xmllint --xpath "string(//Project/PropertyGroup/Version)" RobloxCS/RobloxCS.csproj) + echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Package the project + run: dotnet pack -c Release + + - name: Check if version is already published + id: check_version + run: | + VERSION_EXISTS=$(dotnet nuget search roblox-cs --source "rbxcs" | grep -c "${{ env.PACKAGE_VERSION }}" || true) + echo "VERSION_EXISTS=$VERSION_EXISTS" >> $GITHUB_ENV + + - name: Find and publish the latest package + if: env.VERSION_EXISTS == '0' + run: | + PACKAGE_PATH=$(find ./RobloxCS/bin/Release -name "*.nupkg" -type f -print0 | xargs -0 ls -1t | head -n 1) + dotnet nuget push "$PACKAGE_PATH" --api-key ${{ secrets.GITHUB_TOKEN }} --source "rbxcs" --skip-duplicate + + - name: Version already published + if: env.VERSION_EXISTS != '0' + run: echo "The version is already published. Skipping publish step." \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aad108..a5143b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: branches: [ "master" ] jobs: - build: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/RobloxCS.sln b/RobloxCS.sln index 6ba5e7e..120cc74 100644 --- a/RobloxCS.sln +++ b/RobloxCS.sln @@ -10,8 +10,9 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{44CF4B5D-C4EB-41BF-8D70-20D5213AFA4A}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore - test.cs = test.cs .github\workflows\ci.yml = .github\workflows\ci.yml + test.cs = test.cs + .github\workflows\cd.yml = .github\workflows\cd.yml EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RobloxCS.Tests", "RobloxCS.Tests\RobloxCS.Tests.csproj", "{D63E7B66-97C2-4948-8BAE-FA548C066DCE}"