Skip to content

Commit

Permalink
support different output folder for CI builds
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomGamers committed Aug 19, 2021
1 parent 4768223 commit 63e87db
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 44 deletions.
75 changes: 48 additions & 27 deletions .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import json2toml from "json2toml";
import child_process from "child_process";
import XmlReader from "xml-reader";
import xmlQuery from "xml-query";
import { zip } from 'zip-a-folder';
import fsepkg from 'fs-extra';
import { zip } from "zip-a-folder";
import fsepkg from "fs-extra";
const move = fsepkg.move;
const remove = fsepkg.remove;
import * as core from '@actions/core';
import * as core from "@actions/core";

// Setting it so that it's consistent with installs from thunderstore
const NEBULA_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerMod";
Expand All @@ -36,16 +36,21 @@ const DIST_TSTORE_CLI_CONFIG_PATH = join(
);
const PLUGIN_INFO_PATH = "NebulaPatcher\\PluginInfo.cs";
const pluginInfo = getPluginInfo();
const TSTORE_ARCHIVE_PATH = join(DIST_RELEASE_FOLDER, "nebula-thunderstore.zip");
const GH_ARCHIVE_PATH = join(DIST_RELEASE_FOLDER, "Nebula_" + pluginInfo.version + ".zip");
const TSTORE_ARCHIVE_PATH = join(
DIST_RELEASE_FOLDER,
"nebula-thunderstore.zip"
);
const GH_ARCHIVE_PATH = join(
DIST_RELEASE_FOLDER,
"Nebula_" + pluginInfo.version + ".zip"
);
const MOD_ICON_PATH = "thunderstore_icon.png";
const README_PATH = "README.md";
const CHANGELOG_PATH = "CHANGELOG.md";
const NEBULA_BINARIES_FOLDER = getNebulaFolder();

async function main() {
if (!existsSync(DIST_NEBULA_FOLDER)) {
mkdirSync(DIST_NEBULA_FOLDER, { recursive: true });
throw DIST_NEBULA_FOLDER + " does not exist";
}

if (!existsSync(DIST_TSTORE_CLI_FOLDER)) {
Expand All @@ -54,15 +59,14 @@ async function main() {

try {
generateReleaseBody();
} catch(err) {
} catch (err) {
core.setFailed(err);
}

generateManifest();
copyIcon();
copyReadme();
appendChangelog();
copyFolderContent(NEBULA_BINARIES_FOLDER, DIST_NEBULA_FOLDER);
copyLicenses();

await createTStoreArchive();
Expand Down Expand Up @@ -172,8 +176,7 @@ async function doTStoreRelease() {
return asset.name.includes("tstore-cli.exe");
}

try
{
try {
await downloadRelease(
user,
repo,
Expand All @@ -184,11 +187,10 @@ async function doTStoreRelease() {
disableLogging
);
console.log("Successfully downloaded tstore-cli.exe");
await new Promise(r => setTimeout(r, 2000));
await new Promise((r) => setTimeout(r, 2000));
generateTStoreConfig();
uploadToTStore();
} catch(err)
{
} catch (err) {
console.error(err.message);
}
}
Expand All @@ -205,20 +207,33 @@ function generateTStoreConfig() {

function generateReleaseBody() {
const changelog = readFileSync(CHANGELOG_PATH, "utf-8");
const versionRegExp = new RegExp('\\b[0-9]+\\.[0-9]+(?:\\.[0-9]+)?(?:\\.[0-9]+)?(?=:)\\b', 'g');
const versionRegExp = new RegExp(
"\\b[0-9]+\\.[0-9]+(?:\\.[0-9]+)?(?:\\.[0-9]+)?(?=:)\\b",
"g"
);

const versions = Array.from(changelog.matchAll(versionRegExp));

const currentVersion = versions[0][0];

if(pluginInfo.version != currentVersion)
{
throw `CHANGELOG.md latest version (${currentVersion}) does not match version.json (${pluginInfo.version}) !`;
}
if (pluginInfo.version != currentVersion) {
throw `CHANGELOG.md latest version (${currentVersion}) does not match version.json (${pluginInfo.version}) !`;
}

const body = changelog.substr(versions[0].index + versions[0][0].length + 1, versions[1].index - versions[0].index - versions[0][0].length - versions[1][0].length ).trim();
const body = changelog
.substr(
versions[0].index + versions[0][0].length + 1,
versions[1].index -
versions[0].index -
versions[0][0].length -
versions[1][0].length
)
.trim();

writeFileSync(join(DIST_RELEASE_FOLDER, "BODY.md"), "# Alpha Version " + currentVersion + "\n\n### Changes\n" + body);
writeFileSync(
join(DIST_RELEASE_FOLDER, "BODY.md"),
"# Alpha Version " + currentVersion + "\n\n### Changes\n" + body
);

console.log(body);
}
Expand All @@ -229,9 +244,15 @@ async function createTStoreArchive() {

async function createGHArchive() {
// Ensure contents are within subfolder in zip
await move(DIST_NEBULA_FOLDER, join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME));
await move(
DIST_NEBULA_FOLDER,
join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME)
);
await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH);
await move(join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME), DIST_NEBULA_FOLDER);
await move(
join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME),
DIST_NEBULA_FOLDER
);
await remove(join(DIST_FOLDER, "tmp"));
}

Expand All @@ -240,9 +261,9 @@ function uploadToTStore() {
DIST_TSTORE_CLI_EXE_PATH +
" publish --config " +
DIST_TSTORE_CLI_CONFIG_PATH,
function(err) {
console.error(err);
}
function (err) {
console.error(err);
}
);
}

Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/build-winx64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

# We *only* want to run this if a collaborator or owner of the repo approves a pull request, or if something is merged into the main branch
if: ${{ github.event.ref == 'refs/heads/master' || (github.event.review.state == 'approved' && (github.event.review.author_association == 'COLLABORATOR' || github.event.review.author_association == 'OWNER')) }}
runs-on: dsp-installed
runs-on: windows-latest

env:
Solution_Name: Nebula.sln
Expand All @@ -29,7 +29,10 @@ jobs:

- name: Clear output directory in DSP files
# We use SilentlyContinue here because it errors out if the folder does not exist otherwise
run: rm -R -ErrorAction SilentlyContinue "C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\plugins\Nebula"
run: rm -R -ErrorAction SilentlyContinue "dist\release\nebula"

- name: Add remote build identifier
run: New-Item -Name .remoteBuild -ItemType File -force

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
Expand All @@ -43,8 +46,8 @@ jobs:

# Upload it to the run results
- name: Upload a Build Artifact
uses: actions/[email protected].3
uses: actions/[email protected].4
with:
# Artifact name
name: build-artifacts-${{ matrix.configuration }}
path: C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\plugins\Nebula
path: dist\release\nebula
14 changes: 6 additions & 8 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ on:

jobs:
build:
runs-on: dsp-installed
runs-on: windows-latest

env:
SOLUTION_NAME: Nebula.sln
PLUGIN_PATH : C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\plugins\
NEBULA_FOLDER : Nebula\
NEBULA_FOLDER : dist\\release\\nebula\\
DIST_RELEASE_FOLDER : dist\\release\\

steps:
- name: Set NEBULA_PATH environmental variable
id: nebula-path
run: >
echo "::set-output name=PATH::${{ env.PLUGIN_PATH }}${{ env.NEBULA_FOLDER }}"
- name: Checkout
uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -51,7 +46,10 @@ jobs:

- name: Clear output directory in DSP files
# We use SilentlyContinue here because it errors out if the folder does not exist otherwise
run : rm -R -ErrorAction SilentlyContinue "${{ steps.nebula-path.outputs.PATH }}"
run : rm -R -ErrorAction SilentlyContinue "${{ env.NEBULA_FOLDER }}"

- name: Add remote build identifier
run: copy /b /Y NUL .remoteBuild

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
Expand Down
6 changes: 2 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
<PropertyGroup Label="Game Install Properties">
<DSPGameDir Condition="!Exists('$(DevEnvLoc)')">C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\</DSPGameDir>
<DSPGameDir>$([MSBuild]::EnsureTrailingSlash('$(DSPGameDir)'))</DSPGameDir>
<SteamDir>$([MSBuild]::EnsureTrailingSlash('$(SteamDir)'))</SteamDir>
<BepInExDir>$(DSPGameDir)BepInEx\core\</BepInExDir>
<DSPAssemblyDir>$(DSPGameDir)DSPGAME_Data\Managed\</DSPAssemblyDir>
<PluginOutputDirectory>$(DSPGameDir)BepInEx\plugins\Nebula\</PluginOutputDirectory>
<PropSheetPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</PropSheetPath>
<PluginOutputDirectory Condition="Exists('$(PropSheetPath).remoteBuild')">$(PropSheetPath)dist\release\nebula</PluginOutputDirectory>
</PropertyGroup>

<PropertyGroup Label="Common Properties">
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<OutputPath Condition="Exists('$(DSPGameDir)')">$(PluginOutputDirectory)</OutputPath>
<OutputPath Condition="Exists('$(DSPGameDir)') Or Exists('$(PropSheetPath).remoteBuild')">$(PluginOutputDirectory)</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<TargetFramework>net472</TargetFramework>
<LangVersion>7.3</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion SharedConfig.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
<!-- Note that this is the first target, called by InitialTargets -->
<Target Name="TestDSPGameFolder"
DependsOnTargets="MaybeCopyDevEnv;DevEnvInvalid"
Condition="!Exists('$(DSPGameDir)')" />
Condition="!Exists('$(DSPGameDir)') And !Exists('$(PropSheetPath).remoteBuild')" />
</Project>

0 comments on commit 63e87db

Please sign in to comment.