Skip to content

Commit

Permalink
Merge pull request #200 from Lachee/feat-gh-actions
Browse files Browse the repository at this point in the history
Github Action
  • Loading branch information
Lachee authored Aug 15, 2022
2 parents a9fcc8d + 85fcb5f commit f7295e6
Show file tree
Hide file tree
Showing 51 changed files with 927 additions and 676 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Create Documentation 📚

on:
push:
branches:
- master

jobs:
# Build the documentation
build:
runs-on: ubuntu-latest #windows-latest # Required by DocFX
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
- uses: crazy-max/[email protected]

- name: Install DocFX
run: choco install -y docfx && docfx --version

- name: Use README.md as index.md
run: cp README.md Docfx/index.md

- name: Build Site
run: docfx Docfx/docfx.json -t default,templates/darkfx

# Upload the generated documentation
- name: Upload site artifact
uses: actions/upload-artifact@v1
with:
name: _site
path: _site # Must equals the 'build.dest' value on your docfx.json

# Deploy the generated documentation to the gh-pages branch
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2


# Download the generated documentation
- name: Download site artifact
uses: actions/download-artifact@v1
with:
name: _site

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: _site
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Package 💌

on:
release:
types: [published, released]

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2

- name: Fetch Release Asset
uses: dsaltares/[email protected]
with:
file: "DiscordRichPresence(.[0-9]+)+.nupkg"
version: ${{github.event.release.id}}
regex: true

- name: Publish Package
run: |
dotnet nuget push "**/*.nupkg" -k ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Create Release 📦

on:
push:
branches:
- master

jobs:
# Tag the build
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Klemensas/action-autotag@stable
id: auto-tag
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
tag_prefix: "v"
outputs:
version: "${{steps.auto-tag.outputs.version}}.${{github.run_number}}"
tag: ${{ steps.auto-tag.outputs.tagname }}

# build the packages
build:
runs-on: ubuntu-latest
needs: [ tag ]
steps:
# Check-out repository
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2

# Version the repository
- name: Update Versions
shell: pwsh
run: |
./.github/workflows/scripts/PatchAssemblyInfoVersion.ps1 ${{needs.tag.outputs.version}}
./.github/workflows/scripts/PatchNuspecVersion.ps1 ${{needs.tag.outputs.version}}
# Library Build
- name: Build Library
run: dotnet build DiscordRPC -c Release

- name: Upload Library
uses: actions/[email protected]
with:
name: "netstandard2.0-dll"
path: "DiscordRPC/bin/Release/netstandard2.0"

# Nuget Builds
- name: Build Nuget
run: dotnet pack DiscordRPC -c Release

- name: Upload Nuget
uses: actions/[email protected]
with:
name: "netstandard2.0-nuget"
path: "DiscordRPC/bin/Release/*.nupkg"

# Update the release
release:
runs-on: ubuntu-latest
needs: [ tag, build ]
if: ${{ startsWith(needs.tag.outputs.tag, 'v') }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ needs.tag.outputs.tag }}
prerelease: true
title: Release ${{ needs.tag.outputs.tag }}
files: artifacts/**/*
73 changes: 73 additions & 0 deletions .github/workflows/scripts/PatchAssemblyInfoVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# from http://blogs.msdn.com/b/dotnetinterop/archive/2008/04/21/powershell-script-to-batch-update-assemblyinfo-cs-with-new-version.aspx
#
# SetVersion.ps1
#
# Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
#
# usage:
# from cmd.exe:
# powershell.exe SetVersion.ps1 2.8.3.0
#
# from powershell.exe prompt:
# .\SetVersion.ps1 2.8.3.0
#
# last saved Time-stamp: <Wednesday, April 23, 2008 11:46:40 (by dinoch)>
#


function Usage
{
echo "Usage: ";
echo " from cmd.exe: ";
echo " powershell.exe SetVersion.ps1 2.8.3.0";
echo " ";
echo " from powershell.exe prompt: ";
echo " .\SetVersion.ps1 2.8.3.0";
echo " ";
}


function Update-SourceVersion
{
Param ([string]$Version)
$NewVersion = 'AssemblyVersion("' + $Version + '")';
$NewFileVersion = 'AssemblyFileVersion("' + $Version + '")';

foreach ($o in $input)
{
Write-output $o.FullName
$TmpFile = $o.FullName + ".tmp"

Get-Content $o.FullName -encoding utf8 |
%{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } |
Set-Content $TmpFile -encoding utf8

move-item $TmpFile $o.FullName -force
}
}


function Update-AllAssemblyInfoFiles ( $version )
{
foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" )
{
get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;
}
}


# validate arguments
$r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");

if ($r.Success)
{
Update-AllAssemblyInfoFiles $args[0];
}
else
{
echo " ";
echo "Bad Input!"
echo " ";
Usage ;
}
66 changes: 66 additions & 0 deletions .github/workflows/scripts/PatchNuspecVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# from http://blogs.msdn.com/b/dotnetinterop/archive/2008/04/21/powershell-script-to-batch-update-assemblyinfo-cs-with-new-version.aspx
#
# SetVersion.ps1
#
# Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
#
# usage:
# from cmd.exe:
# powershell.exe SetVersion.ps1 2.8.3.0
#
# from powershell.exe prompt:
# .\SetVersion.ps1 2.8.3.0
#
# last saved Time-stamp: <Wednesday, April 23, 2008 11:46:40 (by dinoch)>
#


function Usage
{
echo "Usage: ";
echo " from cmd.exe: ";
echo " powershell.exe SetVersion.ps1 2.8.3.0";
echo " ";
echo " from powershell.exe prompt: ";
echo " .\SetVersion.ps1 2.8.3.0";
echo " ";
}


function Update-SourceVersion
{
Param ([string]$Version)
$NewVersion = '<version>' + $Version + '</version>';

foreach ($o in $input)
{
Write-output $o.FullName
$TmpFile = $o.FullName + ".tmp"

Get-Content $o.FullName -encoding utf8 |
%{$_ -replace '<version>[0-9]+(\.([0-9]+|\*)){1,3}</version>', $NewVersion } |
Set-Content $TmpFile -encoding utf8

move-item $TmpFile $o.FullName -force
}
}

function Update-AllAssemblyInfoFiles ( $version )
{
get-childitem -Path *.nuspec -recurse | Update-SourceVersion $version;
}

# validate arguments
$r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");

if ($r.Success)
{
Update-AllAssemblyInfoFiles $args[0];
}
else
{
echo " ";
echo "Bad Input!"
echo " ";
Usage ;
}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,8 @@ __pycache__/

# Cake - Uncomment if you are using it
tools/
Thumbs.db
Thumbs.db

# Docfx generation
docs/
_site/
4 changes: 2 additions & 2 deletions DiscordRPC.Example/DiscordRPC.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net45;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
Expand All @@ -13,4 +13,4 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion DiscordRPC.Example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
// [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
7 changes: 5 additions & 2 deletions DiscordRPC/DiscordRPC.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net35;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NuspecFile>DiscordRPC.nuspec</NuspecFile>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
</ItemGroup>
</Project>
</Project>
19 changes: 6 additions & 13 deletions DiscordRPC/DiscordRPC.nuspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/21.0.07/nuspec.xsd">
<id>DiscordRichPresence</id>
<version>0.0.0</version>
<version>1.0.0.0</version>
<authors>Lachee</authors>
<owners>Lachee</owners>
<title>Discord Rich Presence</title>
Expand All @@ -23,23 +23,16 @@ This is an unoffical, non-discord supported library.
<tags>Discord Discord Rich Presence RPC Discord-RPC</tags>

<dependencies>
<group targetFramework="net35">
<dependency id="Newtonsoft.Json" version="12.0.2" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="Newtonsoft.Json" version="12.0.2" />
<group targetFramework="netstandard2.0">
<dependency id="Newtonsoft.Json" version="12.0.2" />
<dependency id="Microsoft.Win32.Registry" version="4.5.0" />
</group>

</group>
</dependencies>
</metadata>

<files>
<file src="./bin/Release/net35/DiscordRPC.dll" target="lib\net35" />
<file src="./bin/Release/net35/DiscordRPC.pdb" target="lib\net35" />
<file src="./bin/Release/net35/DiscordRPC.xml" target="lib\net35" />
<file src="./bin/Release/netstandard2.0/DiscordRPC.dll" target="lib\netstandard2.0" />
<file src="./bin/Release/netstandard2.0/DiscordRPC.pdb" target="lib\netstandard2.0" />
<file src="./bin/Release/netstandard2.0/DiscordRPC.xml" target="lib\netstandard2.0" />
</files>
</package>
</package>
Loading

0 comments on commit f7295e6

Please sign in to comment.