From f07d95f13cfb31d8198a983f8333540c37361de7 Mon Sep 17 00:00:00 2001 From: Keith Date: Sat, 14 Oct 2023 00:07:55 +0800 Subject: [PATCH] Rework versioning system to use Minver (#86) * Fix redundant tmp variable * Add MinVer to generate version numbers * Update workflows to use Minver --- .github/workflows/build.yaml | 6 + .github/workflows/publish-nightly.yaml | 140 ++++------------ .github/workflows/publish.yaml | 151 ++++++++++++++++++ src/Source.targets | 2 +- .../Combat/Damage/DamageCalculator.cs | 8 +- 5 files changed, 193 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2c181a258..17edc15aa 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 \ No newline at end of file diff --git a/.github/workflows/publish-nightly.yaml b/.github/workflows/publish-nightly.yaml index aff26aa03..f23863331 100644 --- a/.github/workflows/publish-nightly.yaml +++ b/.github/workflows/publish-nightly.yaml @@ -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/action-automatic-releases@v1.2.1" - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "nightly" - prerelease: true - title: "Nightly Build (${{ needs.setup.outputs.date }})" - files: "*/*.zip" \ No newline at end of file + - uses: ./.github/workflows/publish.yml + with: + version: ${{ needs.versioning.outputs.version }} + tag: nightly + prerelease: true + draft: false \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 000000000..1add3aa8c --- /dev/null +++ b/.github/workflows/publish.yaml @@ -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/action-automatic-releases@v1.2.1" + 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" \ No newline at end of file diff --git a/src/Source.targets b/src/Source.targets index ecfd8d99f..6f2f9797c 100644 --- a/src/Source.targets +++ b/src/Source.targets @@ -27,5 +27,5 @@ - + \ No newline at end of file diff --git a/src/common/Edelstein.Common.Gameplay.Game/Combat/Damage/DamageCalculator.cs b/src/common/Edelstein.Common.Gameplay.Game/Combat/Damage/DamageCalculator.cs index 3787adceb..e31775104 100644 --- a/src/common/Edelstein.Common.Gameplay.Game/Combat/Damage/DamageCalculator.cs +++ b/src/common/Edelstein.Common.Gameplay.Game/Combat/Damage/DamageCalculator.cs @@ -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; }