Skip to content

Commit

Permalink
finish automation of github releases
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomGamers committed Jul 28, 2021
1 parent bcb69ed commit 3f6cd9c
Show file tree
Hide file tree
Showing 5 changed files with 1,988 additions and 24 deletions.
29 changes: 28 additions & 1 deletion .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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';

// Setting it so that it's consistent with installs from thunderstore
const NEBULA_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerMod";
Expand Down Expand Up @@ -51,6 +52,12 @@ async function main() {
mkdirSync(DIST_TSTORE_CLI_FOLDER, { recursive: true });
}

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

generateManifest();
copyIcon();
copyReadme();
Expand Down Expand Up @@ -84,7 +91,7 @@ function getNebulaFolder() {

if (existsSync(targetsFile)) {
const xml = XmlReader.parseSync(readFileSync(targetsFile, "utf-8"));
var tmpPath = xmlQuery(xml).find("DSPGameDir").text();
const tmpPath = xmlQuery(xml).find("DSPGameDir").text();
if (existsSync(tmpPath)) {
nebulaPath = tmpPath;
}
Expand Down Expand Up @@ -194,6 +201,26 @@ function generateTStoreConfig() {
writeFileSync(DIST_TSTORE_CLI_CONFIG_PATH, json2toml(config));
}

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 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}) !`;
}

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);

console.log(body);
}

async function createTStoreArchive() {
await zip(DIST_NEBULA_FOLDER, TSTORE_ARCHIVE_PATH);
}
Expand Down
74 changes: 53 additions & 21 deletions .github/workflows/bundle-thunderstore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Thunderstore Bundle

on:
workflow_dispatch:
branches: [master]
branches: [test-automatic-release]

jobs:
build:
Expand All @@ -15,39 +15,56 @@ jobs:

steps:
- name: Set NEBULA_PATH environmental variable
id: nebula-path
run: >
echo "NEBULA_PATH=${{ env.PLUGIN_PATH }}${{ env.NEBULA_FOLDER }}" >> $GITHUB_ENV
echo "::set-output name=PATH::${{ env.PLUGIN_PATH }}${{ env.NEBULA_FOLDER }}"
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0 # can't shallowly clone due to git versioning
- run: |
git config user.name '${{ github.actor }}'
git config user.email '${{ github.actor }}@users.noreply.github.com'
git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
- name: Prepare Release
run: >
$version = nbgv prepare-release --format json; >
echo "PREPARE_RELEASE_OUTPUT=$version" >> $GITHUB_ENV
- uses: actions/setup-node@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
cache: 'npm'
- run: npm install @terascope/fetch-github-release
- run: npm install json2toml
- run: npm install xml-reader
- run: npm install xml-query
- run: npm install zip-a-folder
- run: npm install fs-extra

- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

- name: Install dependencies
run: npm ci --ignore-scripts

- 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 "${{ env.NEBULA_PATH }}"
run : rm -R -ErrorAction SilentlyContinue "${{ steps.nebula-path.outputs.PATH }}"

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/[email protected]

# Add dotnet to the PATH: https://github.com/actions/setup-dotnet
- name: Setup dotnet.exe
uses: actions/setup-dotnet@v1
with:
dotnet-version: "3.1.x"
- run: |
dotnet tool install --tool-path . nbgv
# Build it
- name: Build the application
run: msbuild $env:SOLUTION_NAME /p:Configuration=Release /p:PublicRelease=true
Expand All @@ -58,10 +75,25 @@ jobs:
TSTORE_TOKEN: ${{ secrets.TSTORE_TOKEN }}
run: node .github\scripts\thunderstore_bundle.js

- name: Prepare Release
id: prepare-release
run: |
$version = ./nbgv prepare-release --format json;
echo "::set-output name=PREPARE_RELEASE_OUTPUT::$version";
- name: Push changes
run: |
git push;
git checkout ${{ fromJson(steps.prepare-release.outputs.PREPARE_RELEASE_OUTPUT).NewBranch.Name }};
git push -u origin head;
git checkout ${{ fromJson(steps.prepare-release.outputs.PREPARE_RELEASE_OUTPUT).CurrentBranch.Name }}
# Create release
- uses: ncipollo/release-action@v1.8.6
- uses: ncipollo/release-action@v1
with:
artifacts: dist\release\Nebula_${{ fromJson(env.PREPARE_RELEASE_OUTPUT).NewBranch.Version }}.zip
tag: ${{ fromJson(env.PREPARE_RELEASE_OUTPUT).NewBranch.Name }}
commit: ${{ fromJson(env.PREPARE_RELEASE_OUTPUT).NewBranch.Commit }}
artifactErrorsFailBuild: true
bodyFile: "dist\\release\\BODY.md"
artifacts: "dist\\release\\Nebula_${{ fromJson(steps.prepare-release.outputs.PREPARE_RELEASE_OUTPUT).NewBranch.Version }}.zip"
tag: ${{ fromJson(steps.prepare-release.outputs.PREPARE_RELEASE_OUTPUT).NewBranch.Name }}
commit: ${{ fromJson(steps.prepare-release.outputs.PREPARE_RELEASE_OUTPUT).NewBranch.Name }}
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,7 @@ FodyWeavers.xsd

# Jetbrains IDE working folder
.idea/
package-lock.json
package.json

# GitVersioning nbgv prepare-release
.store/
nbgv.exe
Loading

0 comments on commit 3f6cd9c

Please sign in to comment.