Skip to content

Commit

Permalink
Rework versioning system to use Minver (#86)
Browse files Browse the repository at this point in the history
* Fix redundant tmp variable

* Add MinVer to generate version numbers

* Update workflows to use Minver
  • Loading branch information
Kaioru authored Oct 13, 2023
1 parent f032f7c commit f07d95f
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 114 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ jobs:
name: Build

steps:

- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'

- uses: actions/cache@v1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- run: dotnet restore --locked-mode

- name: Build
run: dotnet build --configuration Release

- name: Test
run: dotnet test
140 changes: 34 additions & 106 deletions .github/workflows/publish-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,132 +3,60 @@ name: Publish (Nightly)
on:
schedule:
- cron: "0 0 * * *"

jobs:

setup:
if: github.repository == 'Kaioru/Edelstein'
runs-on: ubuntu-latest

name: Setup
runs-on: ubuntu-latest

outputs:
should_run: ${{ steps.should_run.outputs.should_run }}
date: ${{ steps.date.outputs.date }}
steps:
- uses: actions/checkout@v4
- name: Check current date
id: date
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
- id: should_run
continue-on-error: true
name: Check for new commits
if: ${{ github.event_name == 'schedule' }}
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "should_run=false" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- id: should_run
continue-on-error: true
name: Check for new commits
if: ${{ github.event_name == 'schedule' }}
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "should_run=false" >> $GITHUB_OUTPUT

publish_nuget:
versioning:
needs: setup
if: ${{ needs.setup.outputs.should_run != 'false' }}

name: Versioning
runs-on: ubuntu-latest
name: Publish to Github NuGet Registry

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
- uses: actions/cache@v1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- run: dotnet restore --locked-mode
- name: Pack
run: dotnet pack --configuration Release --version-suffix "nightly.${{ needs.setup.outputs.date }}" --output artifacts
- name: Publish
run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Add VERSION, COMMIT, LICENSE, and README files
run: |
echo "nightly.${{ needs.setup.outputs.date }}" > artifacts/VERSION
echo ${{ github.sha }} > artifacts/COMMIT
cp LICENSE artifacts
cp README.md artifacts
- name: Compress
run: cd artifacts; zip ../packages-nightly.${{ needs.setup.outputs.date }}.zip *; cd ..
- name: Store artifacts
uses: actions/upload-artifact@v3
with:
name: packages-nightly.${{ needs.setup.outputs.date }}
path: packages-nightly.${{ needs.setup.outputs.date }}.zip
fetch-depth: 0

publish_artifacts:
needs: setup
if: ${{ needs.setup.outputs.should_run != 'false' }}
strategy:
matrix:
runtime: [win-x64, win-arm64, osx-x64, osx-arm64, linux-x64, linux-arm64]
runs-on: ubuntu-latest
name: Publish artifacts (${{ matrix.runtime }})
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
- uses: actions/cache@v1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- run: dotnet restore --locked-mode
- name: Install EntityFramework Core tools
run: dotnet tool install --global dotnet-ef
- name: Publish (apps)
run: |
for project in src/app/*/ ; do
dotnet publish $project -c Release -r ${{ matrix.runtime }} --output artifacts-${{ matrix.runtime }} -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:SelfContained=true
done
- name: Bundle migrations (scripts)
run: |
dotnet ef migrations script --project src/common/Edelstein.Common.Database/ --output artifacts-${{ matrix.runtime }}/migrate-01-gameplay.sql --idempotent
dotnet ef migrations script --project src/common/Edelstein.Common.Services.Auth/ --output artifacts-${{ matrix.runtime }}/migrate-02-auth.sql --idempotent
dotnet ef migrations script --project src/common/Edelstein.Common.Services.Server/ --output artifacts-${{ matrix.runtime }}/migrate-03-server.sql --idempotent
dotnet ef migrations script --project src/common/Edelstein.Common.Services.Social/ --output artifacts-${{ matrix.runtime }}/migrate-04-social.sql --idempotent
- name: Add VERSION, COMMIT, LICENSE, and README files
run: |
echo "nightly.${{ needs.setup.outputs.date }}" > artifacts-${{ matrix.runtime }}/VERSION
echo ${{ github.sha }} > artifacts-${{ matrix.runtime }}/COMMIT
cp LICENSE artifacts-${{ matrix.runtime }}
cp README.md artifacts-${{ matrix.runtime }}
- name: Create data, scripts, and plugins directories
run: |
mkdir artifacts-${{ matrix.runtime }}/data
mkdir artifacts-${{ matrix.runtime }}/scripts
mkdir artifacts-${{ matrix.runtime }}/plugins
- name: Publish (plugins)
run: |
for project in src/plugin/*/ ; do
dotnet publish $project -c Release --output artifacts-${{ matrix.runtime }}/plugins/$(basename $project)
done
- name: Compress
run: cd artifacts-${{ matrix.runtime }}; zip -r ../server-${{ matrix.runtime }}-nightly.${{ needs.setup.outputs.date }}.zip . ; cd ..
- name: Store artifacts
uses: actions/upload-artifact@v3
with:
name: server-${{ matrix.runtime }}-nightly.${{ needs.setup.outputs.date }}
path: server-${{ matrix.runtime }}-nightly.${{ needs.setup.outputs.date }}.zip

publish_release:
needs: [setup, publish_artifacts]
- name: Install Minver
run: dotnet tool install --global minver-cli --version 4.3.0

- name: Calculating version
id: version
run: echo "version=$(minver -m 1.0 -p preview -v e)" >> $GITHUB_OUTPUT

publish:
needs: [setup, versioning]
if: ${{ needs.setup.outputs.should_run != 'false' }}

name: Publish
runs-on: ubuntu-latest
name: Publish to Github releases

steps:
- name: Download artifacts
uses: actions/download-artifact@v3
- uses: "marvinpinto/[email protected]"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "nightly"
prerelease: true
title: "Nightly Build (${{ needs.setup.outputs.date }})"
files: "*/*.zip"
- uses: ./.github/workflows/publish.yml
with:
version: ${{ needs.versioning.outputs.version }}
tag: nightly
prerelease: true
draft: false
151 changes: 151 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
on:
workflow_call:
inputs:
version:
required: true
type: string
tag:
type: string
prerelease:
required: true
default: false
type: boolean
draft:
required: true
default: true
type: boolean

jobs:

publish_nuget:
name: Publish to Github Packages
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'

- uses: actions/cache@v1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore
run: dotnet restore --locked-mode

- name: Pack
run: dotnet pack --configuration Release --output artifacts /p:PackageVersion=${{ github.event.inputs.version }}

- name: Publish
run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"

- name: Add VERSION, COMMIT, LICENSE, and README files
run: |
echo ${{ github.event.inputs.version }} > artifacts/VERSION
echo ${{ github.sha }} > artifacts/COMMIT
cp LICENSE artifacts
cp README.md artifacts
- name: Compress
run: cd artifacts; zip ../packages-${{ github.event.inputs.version }}.zip *; cd ..

- name: Store artifacts
uses: actions/upload-artifact@v3
with:
name: packages-${{ github.event.inputs.version }}
path: packages-${{ github.event.inputs.version }}.zip

publish_artifact:
strategy:
matrix:
runtime: [win-x64, win-arm64, osx-x64, osx-arm64, linux-x64, linux-arm64]

name: Publish artifacts (${{ matrix.runtime }})
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'

- uses: actions/cache@v1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore
run: dotnet restore --locked-mode

- name: Install EntityFramework Core tools
run: dotnet tool install --global dotnet-ef

- name: Publish (apps)
run: |
for project in src/app/*/ ; do
dotnet publish $project -c Release -r ${{ matrix.runtime }} --output artifacts-${{ matrix.runtime }} -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:SelfContained=true
done
- name: Bundle migrations (scripts)
run: |
dotnet ef migrations script --project src/common/Edelstein.Common.Database/ --output artifacts-${{ matrix.runtime }}/migrate-01-gameplay.sql --idempotent
dotnet ef migrations script --project src/common/Edelstein.Common.Services.Auth/ --output artifacts-${{ matrix.runtime }}/migrate-02-auth.sql --idempotent
dotnet ef migrations script --project src/common/Edelstein.Common.Services.Server/ --output artifacts-${{ matrix.runtime }}/migrate-03-server.sql --idempotent
dotnet ef migrations script --project src/common/Edelstein.Common.Services.Social/ --output artifacts-${{ matrix.runtime }}/migrate-04-social.sql --idempotent
- name: Add VERSION, COMMIT, LICENSE, and README files
run: |
echo ${{ github.event.inputs.version }} > artifacts-${{ matrix.runtime }}/VERSION
echo ${{ github.sha }} > artifacts-${{ matrix.runtime }}/COMMIT
cp LICENSE artifacts-${{ matrix.runtime }}
cp README.md artifacts-${{ matrix.runtime }}
- name: Create data, scripts, and plugins directories
run: |
mkdir artifacts-${{ matrix.runtime }}/data
mkdir artifacts-${{ matrix.runtime }}/scripts
mkdir artifacts-${{ matrix.runtime }}/plugins
- name: Publish (plugins)
run: |
for project in src/plugin/*/ ; do
dotnet publish $project -c Release --output artifacts-${{ matrix.runtime }}/plugins/$(basename $project)
done
- name: Compress artifacts
run: cd artifacts-${{ matrix.runtime }}; zip -r ../server-${{ matrix.runtime }}-${{ github.event.inputs.version }}.zip . ; cd ..

- name: Store artifacts
uses: actions/upload-artifact@v3
with:
name: server-${{ matrix.runtime }}-${{ github.event.inputs.version }}
path: server-${{ matrix.runtime }}-${{ github.event.inputs.version }}.zip

publish_release:
needs: [publish_artifacts]

name: Publish to Github releases
runs-on: ubuntu-latest

steps:
- name: Download artifacts
uses: actions/download-artifact@v3

- uses: "marvinpinto/[email protected]"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ github.event.inputs.tag }}"
prerelease: ${{ github.event.inputs.prerelease }}
draft: ${{ github.event.inputs.draft }}
title: "${{ github.event.inputs.version }}"
files: "*/*.zip"
2 changes: 1 addition & 1 deletion src/Source.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
<None Include="../../../README.md" Pack="true" PackagePath="/"/>
<None Include="../../../LICENSE" Pack="true" PackagePath="/"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,7 @@ itemDual is IItemSlotEquip equipDual &&
private static double GetRandomInRange(uint rand, double f0, double f1)
{
if (Math.Abs(f0 - f1) < 0.0001) return f0;
if (f0 > f1)
{
var tmp = f1;
f0 = f1;
f1 = tmp;
}

if (f0 > f1) (f0, f1) = (f1, f0);
return f0 + rand % 10000000 * (f1 - f0) / 9999999.0;
}

Expand Down

0 comments on commit f07d95f

Please sign in to comment.