Skip to content

Commit

Permalink
update nuget pipeline
Browse files Browse the repository at this point in the history
update script
  • Loading branch information
RaidMax committed Jun 28, 2024
1 parent c54ff5d commit 9cdb2ca
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 489 deletions.
188 changes: 188 additions & 0 deletions .github/workflows/build_application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: Application build

on:
push:
branches: [ develop, release/pre, master ]
paths:
- Application/**
- .github/workflows/build_application.yml
pull_request:
branches: [ develop ]
paths:
- Application/**

env:
releaseType: prerelease

jobs:
make_version:
runs-on: ubuntu-latest
outputs:
build_num: ${{ steps.generate_build_number.outputs.build_num }}

steps:
- name: Make build number
id: generate_build_number
run: |
build_num=$(date +'%Y.%-m.%-d').$(date +'%3N' | sed 's/^0*//')
echo "build_num=$build_num" >> $GITHUB_OUTPUT
echo "Build number is $build_num"
build:
runs-on: ubuntu-latest
needs: [ make_version ]

env:
solution: IW4MAdmin.sln
buildConfiguration: Prerelease
isPreRelease: false

buildPlatform: Any CPU
outputFolder: ${{ github.workspace }}/Publish/Prerelease
buildNumber: ${{ needs.make_version.outputs.build_num }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore NuGet packages
run: dotnet restore ${{ env.solution }}

- name: Preload external resources
run: |
echo "Build Configuration is ${{ env.buildConfiguration }}, Release Type is ${{ env.releaseType }}"
mkdir -p WebfrontCore/wwwroot/lib/open-iconic/font/css
curl -o WebfrontCore/wwwroot/lib/open-iconic/font/css/open-iconic-bootstrap-override.scss https://raw.githubusercontent.com/iconic/open-iconic/master/font/css/open-iconic-bootstrap.scss
sed -i 's#../fonts/#/font/#g' WebfrontCore/wwwroot/lib/open-iconic/font/css/open-iconic-bootstrap-override.scss
- name: Build webfront
run: dotnet build WebfrontCore/WebfrontCore.csproj -c ${{ env.buildConfiguration }} /p:Configuration=${{ env.buildConfiguration }} /p:Platform="x64"

- name: Compile SCSS files
run: |
dotnet tool install Excubo.WebCompiler --global
webcompiler -r WebfrontCore/wwwroot/css/src -o WebfrontCore/wwwroot/css/ -m disable -z disable
webcompiler WebfrontCore/wwwroot/lib/open-iconic/font/css/open-iconic-bootstrap-override.scss -o WebfrontCore/wwwroot/css/ -m disable -z disable
- name: Bundle JS files
run: |
echo 'Getting dotnet bundle'
curl -o ${{ github.workspace }}/dotnet-bundle.zip https://raidmax.org/IW4MAdmin/res/dotnet-bundle.zip
echo 'Unzipping download'
unzip ${{ github.workspace }}/dotnet-bundle.zip -d ${{ github.workspace }}/bundle
echo 'Executing dotnet-bundle'
cd ${{ github.workspace }}/bundle
dotnet dotnet-bundle.dll clean ${{ github.workspace }}/WebfrontCore/bundleconfig.json
dotnet dotnet-bundle.dll ${{ github.workspace }}/WebfrontCore/bundleconfig.json
- name: Build plugins
run: |
cd Plugins
find . -name "*.csproj" -print0 | xargs -0 -I {} dotnet publish {} -c ${{ env.buildConfiguration }} -o ../BUILD/Plugins /p:Configuration=${{ env.buildConfiguration }} /p:Platform="x64" /p:DeployOnBuild=false /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:Version=${{ env.buildNumber }} --no-restore
- name: Build application
run: dotnet publish Application/Application.csproj -c ${{ env.buildConfiguration }} -o ${{ env.outputFolder }} /p:Version=${{ env.buildNumber }} /p:Configuration=${{ env.buildConfiguration }} /p:Platform="x64" --no-restore

- name: Download translations
run: |
mkdir -p "${{ env.outputFolder }}/Localization"
localizations=("en-US" "ru-RU" "es-EC" "pt-BR" "de-DE")
for localization in "${localizations[@]}"
do
url="https://master.iw4.zip/localization/$localization"
filePath="${{ env.outputFolder }}/Localization/IW4MAdmin.$localization.json"
curl -s "$url" -o "$filePath"
done
- name: Clean up publish files
run: |
chmod +x ${{ github.workspace }}/Application/BuildScripts/PostBuild.sh
bash ${{ github.workspace }}/Application/BuildScripts/PostBuild.sh ${{ env.outputFolder }} ${{ github.workspace }}
- name: Generate start scripts
run: |
cat << EOF > "${{ env.outputFolder }}/StartIW4MAdmin.cmd"
@echo off
@title IW4MAdmin
set DOTNET_CLI_TELEMETRY_OPTOUT=1
dotnet Lib\IW4MAdmin.dll
pause
EOF
cat << EOF > "${{ env.outputFolder }}/StartIW4MAdmin.sh"
#!/bin/bash
export DOTNET_CLI_TELEMETRY_OPTOUT=1
dotnet Lib/IW4MAdmin.dll
EOF
- name: Move extra content into publish directory
run: |
cp ${{ github.workspace }}/Plugins/ScriptPlugins/*.js ${{ env.outputFolder }}/Plugins/
cp ${{ github.workspace }}/BUILD/Plugins/*.dll ${{ env.outputFolder }}/Plugins/
mkdir ${{ env.outputFolder }}/wwwroot/css
cp ${{ github.workspace }}/WebfrontCore/wwwroot/css/global.min.css ${{ env.outputFolder }}/wwwroot/css/global.min.css
mkdir ${{ env.outputFolder }}/wwwroot/js
cp ${{ github.workspace }}/WebfrontCore/wwwroot/js/global.min.js ${{ env.outputFolder }}/wwwroot/js/global.min.js
rsync -a ${{ github.workspace }}/WebfrontCore/font/ ${{ env.outputFolder }}/wwwroot/font/
rsync -a ${{ github.workspace }}/GameFiles/ ${{ env.outputFolder }}/
rsync -a ${{ github.workspace }}/BUILD/Plugins/wwwroot/ ${{ env.outputFolder }}/wwwroot/
- name: Upload artifact for analysis
uses: actions/upload-artifact@v4
with:
name: IW4MAdmin-${{ env.buildNumber }}
path: ${{ env.outputFolder }}

release_github:
runs-on: ubuntu-latest
needs: [ make_version, build ]
permissions:
contents: write
environment: prerelease
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release/pre' }}

env:
buildNumber: ${{ needs.make_version.outputs.build_num }}

steps:
- name: Download build
uses: actions/download-artifact@v4
with:
name: IW4MAdmin-${{ env.buildNumber }}
path: ${{ github.workspace }}

- name: Zip build
run: zip -r IW4MAdmin-${{ env.buildNumber }}.zip ${{ github.workspace }}/*

- name: Make release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.buildNumber }}-${{ env.releaseType }}
name: IW4MAdmin ${{ env.buildNumber }}
draft: true
prerelease: true
body: Automated rolling release - changelog below. [Updating Instructions](https://github.com/RaidMax/IW4M-Admin/wiki/Getting-Started#updating)
generateReleaseNotes: true
artifacts: ${{ github.workspace }}/*.zip
artifactErrorsFailBuild: true

update_master_version:
runs-on: ubuntu-latest
needs: [ make_version, build, release_github ]
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release/pre' }}

env:
buildNumber: ${{ needs.make_version.outputs.build_num }}

steps:
- name: Update master version
run: |
curl --header "Content-Type: application/json" \
--request POST \
--data '{"current-version-${{ env.releaseType }}":"${{ env.buildNumber }}","jwt-secret": "${{ secrets.JWTSecret }}"}' \
http://api.raidmax.org:5000/version
93 changes: 61 additions & 32 deletions .github/workflows/shared_library_nuget.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,73 @@
name: Build and Pack SharedLibraryCore Nuget
name: SharedLibraryCore NuGet

on:
push:
branches: [ "develop" ]
branches: [ develop ]
paths:
- SharedLibraryCore/**
- .github/workflows/shared_library_nuget.yml
pull_request:
branches: [ "develop" ]
branches: [ develop ]
paths:
- SharedLibraryCore/**

env:
outputDirectory: ${{ github.workspace}}/nuget
buildConfiguration: Prerelease

jobs:
build_pack:

runs-on: ubuntu-latest

env:
buildConfiguration: 'Prerelease'
outputs:
build_num: ${{ steps.generate_build_number.outputs.build_num }}

steps:
- name: Make build number
id: generate_build_number
run: |
build_num=$(date +'%Y.%-m.%-d').$(date +'%3N' | sed 's/^0*//')
echo "build_num=$build_num" >> $GITHUB_ENV
echo "build_num=$build_num" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build Data
run: dotnet build **/Data.csproj -c ${{env.buildConfiguration}} /p:Version=${{ env.build_num }} --no-restore
- name: Build SLC
run: dotnet build **/SharedLibraryCore.csproj -c ${{env.buildConfiguration}} /p:Version=${{ env.build_num }} --no-restore
- name: Pack SLC
run: dotnet pack **/SharedLibraryCore.csproj -c ${{env.buildConfiguration}} -p:PackageVersion=${{ env.build_num }} -o ${{ env.outputDirectory }}

- name: Publish nuget package artifact
uses: actions/upload-artifact@v4
with:
name: SharedLibraryCore-${{ steps.generate_build_number.outputs.build_num }}
path: ${{ env.outputDirectory }}/*.nupkg

publish:
runs-on: ubuntu-latest

needs: [ build_pack ]

steps:
- name: Make build number
id: generate_build_number
run: |
echo "build_num=$(date +'%Y.%m.%d').$(( $(date +'%H') + $(date +'%M') + $(date +'%S') + $(date +'%3N') ))" >> "$GITHUB_OUTPUT"
- name: Display build number
run: echo "$build_num"
env:
release_name: ${{ steps.generate_build_number.build_num }}
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build Data
run: dotnet build **/Data.csproj -c ${{env.buildConfiguration}} --no-restore
- name: Build SLC
run: dotnet build **/SharedLibraryCore.csproj -c ${{env.buildConfiguration}} /p:Version=${{env.release_name}} --no-restore
- name: Pack SLC
run: dotnet pack **/SharedLibraryCore.csproj -c ${{env.buildConfiguration}} --version-suffix ${{env.release_name}}
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: SharedLibraryCore-${{ needs.build_pack.outputs.build_num }}
path: ${{ env.outputDirectory }}

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Publish nuget package artifact
uses: actions/upload-artifact@v3
with:
name: SharedLibraryCore.${{env.release_name}}.nupkg
path: '**/RaidMax.IW4MAdmin.SharedLibraryCore.${{env.release_name}}.nupkg'
- name: Publish NuGet package
run: |
for file in ${{ env.outputDirectory }}/*.nupkg; do
dotnet nuget push "$file" --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
done
14 changes: 0 additions & 14 deletions Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,4 @@
</None>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="if $(ConfigurationName) == Debug call $(ProjectDir)BuildScripts\PreBuild.bat $(ProjectDir)..\ $(ProjectDir) $(TargetDir) $(OutDir)" />
</Target>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="CurrentAssembly" />
</GetAssemblyIdentity>
<Exec Command="if $(ConfigurationName) == Debug call $(ProjectDir)BuildScripts\PostBuild.bat $(ProjectDir)..\ $(ProjectDir) $(TargetDir) $(OutDir) %25(CurrentAssembly.Version)" />
</Target>

<Target Name="PostPublish" AfterTargets="Publish">
<Exec Command="if $(ConfigurationName) == Debug call $(ProjectDir)BuildScripts\PostPublish.bat $(ProjectDir)..\ $(ProjectDir) $(TargetDir) $(ConfigurationName)" />
</Target>
</Project>
50 changes: 50 additions & 0 deletions Application/BuildScripts/PostBuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

PublishDir="$1"
SourceDir="$2"

if [ -z "$PublishDir" ] || [ -z "$SourceDir" ]; then
echo "Usage: $0 <PublishDir> <SourceDir>"
exit 1
fi

echo "Deleting extra runtime files"
declare -a runtimes=("linux-arm" "linux-arm64" "linux-armel" "osx" "osx-x64" "win-arm" "win-arm64" "alpine-x64" "linux-musl-x64")
for runtime in "${runtimes[@]}"; do
if [ -d "$PublishDir/runtimes/$runtime" ]; then
rm -rf "$PublishDir/runtimes/$runtime"
fi
done

echo "Deleting misc files"
if [ -f "$PublishDir/web.config" ]; then rm "$PublishDir/web.config"; fi
if [ -f "$PublishDir/libman.json" ]; then rm "$PublishDir/libman.json"; fi
rm -f "$PublishDir"/*.exe
rm -f "$PublishDir"/*.pdb
rm -f "$PublishDir"/IW4MAdmin

echo "Setting up default folders"
mkdir -p "$PublishDir/Plugins"
mkdir -p "$PublishDir/Configuration"
mv "$PublishDir/DefaultSettings.json" "$PublishDir/Configuration/"

mkdir -p "$PublishDir/Lib"
rm -f "$PublishDir/Microsoft.CodeAnalysis*.dll"
mv "$PublishDir"/*.dll "$PublishDir/Lib/"
mv "$PublishDir"/*.json "$PublishDir/Lib/"
mv "$PublishDir/runtimes" "$PublishDir/Lib/runtimes"
mv "$PublishDir/ru" "$PublishDir/Lib/ru"
mv "$PublishDir/de" "$PublishDir/Lib/de"
mv "$PublishDir/pt" "$PublishDir/Lib/pt"
mv "$PublishDir/es" "$PublishDir/Lib/es"
rm -rf "$PublishDir/cs"
rm -rf "$PublishDir/fr"
rm -rf "$PublishDir/it"
rm -rf "$PublishDir/ja"
rm -rf "$PublishDir/ko"
rm -rf "$PublishDir/pl"
rm -rf "$PublishDir/pt-BR"
rm -rf "$PublishDir/tr"
rm -rf "$PublishDir/zh-Hans"
rm -rf "$PublishDir/zh-Hant"
if [ -d "$PublishDir/refs" ]; then mv "$PublishDir/refs" "$PublishDir/Lib/refs"; fi
9 changes: 0 additions & 9 deletions DeploymentFiles/PostPublish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,3 @@ foreach($localization in $localizations)
$response = Invoke-WebRequest $url -UseBasicParsing
Out-File -FilePath $filePath -InputObject $response.Content -Encoding utf8
}

$versionInfo = (Get-Command ("{0}\IW4MAdmin.exe" -f $PublishDir)).FileVersionInfo
$json = @{
Major = $versionInfo.ProductMajorPart
Minor = $versionInfo.ProductMinorPart
Build = $versionInfo.ProductBuildPart
Revision = $versionInfo.ProductPrivatePart
}
$json | ConvertTo-Json | Out-File -FilePath ("{0}\VersionInformation.json" -f $PublishDir) -Encoding ASCII
Loading

0 comments on commit 9cdb2ca

Please sign in to comment.