Publish (Nightly) #400
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish (Nightly) | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
setup: | |
if: github.repository == 'Kaioru/Edelstein' | |
runs-on: ubuntu-latest | |
name: Setup | |
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 | |
publish_nuget: | |
needs: setup | |
if: ${{ needs.setup.outputs.should_run != 'false' }} | |
runs-on: ubuntu-latest | |
name: Publish to Github NuGet Registry | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: '7.0.x' | |
- uses: actions/cache@v3 | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-nuget | |
- 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 | |
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@v1 | |
with: | |
dotnet-version: '7.0.x' | |
- uses: actions/cache@v3 | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-nuget | |
- 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] | |
if: ${{ needs.setup.outputs.should_run != 'false' }} | |
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" |