Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflows/publish-nuget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Build & Publish NuGet Package

on:
push:
branches:
- master
release:
types: [created]

permissions:
contents: write
packages: write

jobs:
build-and-publish:
runs-on: ubuntu-latest
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
submodules: 'recursive'

- name: Set up .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'

- name: Download OpenVR Dependencies
run: |
curl -L -o openvr_api.cs https://raw.githubusercontent.com/ValveSoftware/openvr/master/headers/openvr_api.cs

- name: Restore dependencies
run: dotnet restore

- name: Build the project
run: dotnet build --configuration Release --no-restore

- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" == "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
else
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
BASE_VERSION="${LATEST_TAG#v}"
MAJOR=$(echo $BASE_VERSION | cut -d. -f1)
MINOR=$(echo $BASE_VERSION | cut -d. -f2)
PATCH=$(echo $BASE_VERSION | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-preview.${{ github.run_number }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Pack the project
run: dotnet pack --configuration Release --no-build -o ./nupkg -p:Version=${{ steps.version.outputs.version }}

- name: Upload package as artifact
id: upload-artifact
uses: actions/upload-artifact@v7
with:
name: nuget-package
path: ./nupkg/*.nupkg

- name: Upload package to release
id: upload-release
if: github.event_name == 'release'
run: gh release upload ${{ github.event.release.tag_name }} ./nupkg/*.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Push package to GitHub Packages
id: push-github
run: |
dotnet nuget add source \
--username ${{ github.actor }} \
--password ${{ secrets.GITHUB_TOKEN }} \
--store-password-in-clear-text \
--name github \
"https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
dotnet nuget push ./nupkg/*.nupkg --source github --skip-duplicate

- name: Push package to NuGet
id: push-nuget
if: github.event_name == 'release' && env.NUGET_API_KEY != ''
run: dotnet nuget push ./nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ env.NUGET_API_KEY }} --skip-duplicate

- name: Job summary
if: always()
run: |
echo "## NuGet Package" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Links" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.upload-artifact.outcome }}" == "success" ]; then
echo "- [Artifact (this run)](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts)" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.push-github.outcome }}" == "success" ]; then
echo "- [GitHub Packages](https://github.com/${{ github.repository }}/pkgs/nuget/EasyOpenVR)" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.upload-release.outcome }}" == "success" ]; then
echo "- [GitHub Release](https://github.com/${{ github.repository }}/releases/tag/${{ github.event.release.tag_name }})" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.push-nuget.outcome }}" == "success" ]; then
echo "- [NuGet.org](https://www.nuget.org/packages/EasyOpenVR/${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
fi
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "EasyUtils"]
path = EasyUtils
url = https://github.com/BOLL7708/EasyUtils.git
15 changes: 15 additions & 0 deletions EasyOpenVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>14</LangVersion>

<PackageId>EasyOpenVR</PackageId>
<Authors>BOLL7708</Authors>
<Description>This is a Class Library to make it easier to talk to the OpenVR API using the official C# headers</Description>
<PackageTags>openvr steamvr openvr-api</PackageTags>
<PackageProjectUrl>https://github.com/BOLL7708/EasyOpenVR</PackageProjectUrl>
<RepositoryUrl>https://github.com/BOLL7708/EasyOpenVR</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,4 +28,9 @@
<PackageReference Include="System.Text.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
<None Include="LICENSE.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>