Skip to content

thing

thing #163

Workflow file for this run

name: Release
on:
push:
branches:
- main
jobs:
prerelease:
name: Prerelease
runs-on: ubuntu-latest
environment: Release
outputs:
csharp_changesets: ${{ toJson(fromJson(steps.changesets.outputs.result).csharp) }}
web_changesets: ${{ toJson(fromJson(steps.changesets.outputs.result).web) }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up toolchain
# flatbuffers-compiler at version 2.0.6 is only available on 22.10 but we don't need it anyway
# run: sudo apt install -y mono-devel flatbuffers-compiler=2.0.6
run: sudo apt install -y mono-devel flatbuffers-compiler
- name: Install dependencies
run: nuget restore SlzSpeedrunTools.sln
- name: Build
run: msbuild
- name: Prepare for nightly release
run: csi ./scripts/CopyBuildsToBin.csx
- name: Create nightly release
uses: softprops/action-gh-release@v1
with:
prerelease: true
target_commitish: ${{ github.sha }}
tag_name: dev_${{ github.run_number }}
body: >
**DO NOT DOWNLOAD** unless either I told you to or you know what you're doing. Instead look these mods up on Thunderstore and download them from there.
These are testing builds used for development of the mods. They contain the most recent changes which are usually untested and broken. Use at your own risk.
files: ./bin/*.dll
- name: Load changesets
id: changesets
uses: actions/github-script@v6
with:
script: |
const path = require("path");
const fs = require("fs");
const changesets = fs
.readdirSync("changesets")
.map((filename) => path.parse(filename))
.filter(
(file) =>
file.ext.toLowerCase() === ".md" && file.name !== "README"
)
.map((file) => {
const parts = file.name.split("_");
return {
filename: file.base,
game: parts[0],
project: parts[1],
version_bump_type: parts[2],
changelog_description: fs.readFileSync(
path.join("changesets", file.base),
"utf-8"
),
};
});
return {
web: changesets.filter(changeset => changeset.game === "Web"),
csharp: changesets.filter(changeset => changeset.game !== "Web"),
};
release-csharp:
name: Release (C#)
runs-on: ubuntu-latest
environment: Release
needs: prerelease
if: ${{ needs.prerelease.outputs.csharp_changesets != '[]' }}
strategy:
matrix:
changeset: ${{ fromJson(needs.prerelease.outputs.csharp_changesets) }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up toolchain
# flatbuffers-compiler at version 2.0.6 is only available on 22.10 but we don't need it anyway
# run: sudo apt install -y mono-devel flatbuffers-compiler=2.0.6
run: sudo apt install -y mono-devel
- name: Install dependencies
run: nuget restore SlzSpeedrunTools.sln
- name: Bump version
id: bump_version
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
VERSION_BUMP_TYPE: ${{ matrix.changeset.version_bump_type }}
CHANGELOG_DESCRIPTION: ${{ matrix.changeset.changelog_description }}
run: csi ./scripts/Release.csx "$GAME" "$PROJECT" "$VERSION_BUMP_TYPE" "$CHANGELOG_DESCRIPTION"
- name: Build
run: msbuild /property:Configuration=Release
- name: Get Thunderstore package details
id: thunderstore_details
if: steps.bump_version.outputs.release_thunderstore == 'true'
uses: actions/github-script@v6
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
NEW_VERSION: ${{ steps.bump_version.outputs.new_version }}
with:
script: |
const fs = require("fs");
const path = require("path");
const project = process.env["PROJECT"];
const game = process.env["GAME"];
const gameLower = game.toLowerCase();
const projectDir = path.join("projects", game, project);
const readmeContents = fs.readFileSync(
path.join(projectDir, "README.md"),
"utf8"
);
const changelogContents = fs.readFileSync(
path.join(projectDir, "CHANGELOG.md"),
"utf8"
);
const manifest = JSON.parse(
fs.readFileSync(
path.join(projectDir, "thunderstore", "manifest.json"),
"utf8"
)
);
const filesDir = path.join(projectDir, "thunderstore", "files");
const modsDir = path.join(filesDir, "Mods");
fs.mkdirSync(modsDir, { recursive: true });
fs.copyFileSync(
path.join(projectDir, "bin", "Release", `${project}.dll`),
path.join(modsDir, `${project}.dll`)
);
fs.writeFileSync(
path.join(filesDir, "README.md"),
`${readmeContents}\n# Changelog\n\n${changelogContents}`
);
fs.copyFileSync(
path.join(projectDir, "thunderstore", "icon.png"),
path.join(filesDir, "icon.png")
);
return {
repo: `${gameLower}.thunderstore.io`,
community: gameLower,
namespace: "jakzo",
name: project,
version: process.env["NEW_VERSION"],
description: readmeContents.split("\n\n", 1)[0],
website: `https://github.com/jakzo/SlzSpeedrunTools/tree/main/projects/${game}/${project}`,
deps: manifest.dependencies.map((dep) => dep.replace(/-([^-]+)$/, "@$1")).join(" "),
path: filesDir,
};
- name: Release to Thunderstore
uses: GreenTF/[email protected]
if: steps.bump_version.outputs.release_thunderstore == 'true'
with:
token: ${{ secrets.THUNDERSTORE_API_TOKEN }}
repo: ${{ fromJson(steps.thunderstore_details.outputs.result).repo }}
community: ${{ fromJson(steps.thunderstore_details.outputs.result).community }}
namespace: ${{ fromJson(steps.thunderstore_details.outputs.result).namespace }}
name: ${{ fromJson(steps.thunderstore_details.outputs.result).name }}
version: ${{ fromJson(steps.thunderstore_details.outputs.result).version }}
description: ${{ fromJson(steps.thunderstore_details.outputs.result).description }}
website: ${{ fromJson(steps.thunderstore_details.outputs.result).website }}
deps: ${{ fromJson(steps.thunderstore_details.outputs.result).deps }}
path: ${{ fromJson(steps.thunderstore_details.outputs.result).path }}
- name: Copy LiveSplit build for commit
if: steps.bump_version.outputs.release_livesplit == 'true'
env:
GAME: ${{ matrix.changeset.game }}
PROJECT: ${{ matrix.changeset.project }}
run: |
set -eux
DLL_NAME="$PROJECT.dll"
cd "./projects/$GAME/$PROJECT"
mkdir -p "./Components"
cp "./bin/Release/$DLL_NAME" "./Components/$DLL_NAME"
- name: Commit version bump
run: |
set -eux
rm "./changesets/${{ matrix.changeset.filename }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Release" --no-verify
for i in {1..3}; do
git fetch
if ! git rebase --autostash --no-verify; then
git rebase --abort
echo "Failed to rebase with main, probably due to git conflict. Manual fix required..."
exit 1
fi
if git push --no-verify; then
exit 0
fi
done
exit 1
- name: Create release
uses: softprops/action-gh-release@v1
with:
target_commitish: ${{ github.sha }}
tag_name: "${{ matrix.changeset.game }}${{ matrix.changeset.project }}_v${{ steps.bump_version.outputs.new_version }}"
body: ${{ steps.bump_version.outputs.changelog }}
files: |
./projects/${{ matrix.changeset.game }}/${{ matrix.changeset.project }}/thunderstore/*.zip
./projects/${{ matrix.changeset.game }}/${{ matrix.changeset.project }}/bin/Release/${{ matrix.changeset.project }}.dll
release-web:
name: Release (JS)
runs-on: ubuntu-latest
environment: Release
needs: prerelease
permissions:
pages: write
id-token: write
contents: write
if: ${{ needs.prerelease.outputs.web_changesets != '[]' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18.x
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Bump versions
uses: actions/github-script@v6
env:
CHANGESETS: ${{ needs.prerelease.outputs.web_changesets }}
with:
script: |
const fs = require("fs");
const path = require("path");
const cp = require("child_process");
for (const changeset of JSON.parse(process.env.CHANGESETS)) {
const projectPath = path.join("projects", changeset.game, changeset.project);
const changelogPath = path.join(projectPath, "CHANGELOG.md");
const packageJson = JSON.parse(
fs.readFileSync(path.join(projectPath, "package.json"), "utf8")
);
const result = cp.spawnSync(
"npm",
[
"-w",
packageJson.name,
"version",
"--no-git-tag-version",
changeset.version_bump_type.toLowerCase(),
],
{ stdio: "inherit" }
);
if (result.status) throw new Error("Command failed");
const packageJson2 = JSON.parse(
fs.readFileSync(path.join(projectPath, "package.json"), "utf8")
);
const oldChangelog = fs.readFileSync(changelogPath, "utf8");
fs.writeFileSync(
changelogPath,
`## ${packageJson2.version}\n\n${changeset.changelog_description}\n\n${oldChangelog}`
);
fs.unlinkSync(path.join("changesets", changeset.filename));
}
- name: Build
run: npm -ws run build
- name: Publish to npm
uses: actions/github-script@v6
env:
CHANGESETS: ${{ needs.prerelease.outputs.web_changesets }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
script: |
const fs = require("fs");
const path = require("path");
const cp = require("child_process");
for (const changeset of JSON.parse(process.env.CHANGESETS)) {
const projectPath = path.join("projects", changeset.game, changeset.project);
const packageJson = JSON.parse(
fs.readFileSync(path.join(projectPath, "package.json"), "utf8")
);
if (packageJson.private) continue;
const result = cp.spawnSync(
"npm",
["-w", packageJson.name, "publish", "--access=public"],
{ stdio: "inherit" }
);
if (result.status) throw new Error("Command failed");
}
- name: Commit version bumps
run: |
set -eux
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Release" --no-verify
git push --no-verify
- name: Check if should deploy pages
id: deploy_pages
uses: actions/github-script@v6
env:
CHANGESETS: ${{ needs.prerelease.outputs.web_changesets }}
with:
script: |
var projects = new Set(JSON.parse(process.env.CHANGESETS).map(changeset => changeset.project));
console.log(projects);
return ["vr-input-viewer"].some(name => projects.has(name));
- name: Bundle pages
if: ${{ steps.deploy_pages.outputs.result == 'true' }}
run: ./pages/build.sh
- name: Upload vr.jf.id.au
uses: SamKirkland/[email protected]
with:
server: ftpupload.net
protocol: ftps
username: if0_34708249
password: ${{ secrets.IF_FTP_PASSWORD }}
local-dir: ./pages/dist/vr.jf.id.au/
server-dir: ./vr.jf.id.au/htdocs/
- name: Upload pages artifact
if: ${{ steps.deploy_pages.outputs.result == 'true' }}
uses: actions/upload-pages-artifact@v2
with:
path: ./pages/dist/github-pages
- name: Deploy pages
if: ${{ steps.deploy_pages.outputs.result == 'true' }}
uses: actions/deploy-pages@v2