Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI #15

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/attachReleaseArtifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: "Attach Release Artifacts"

# Controls when the action will run.
on:
release:
types: [published]

env:
KSP_ROOT: /tmp/ksp

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
attach-release-artifacts:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Get Branch
shell: bash
run: |
releaseBranch=${{ github.event.release.target_commitish }}
echo "Found branch ${releaseBranch}"
echo "tagged_branch=${releaseBranch}" >> $GITHUB_ENV

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ env.tagged_branch }}

- name: Download required assemblies
id: download-assemblies
uses: KSP-RO/BuildTools/download-assemblies-v2@master
with:
KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }}

- name: Update AssemblyInfo
uses: KSP-RO/BuildTools/update-assembly-info@master
with:
path: ${{ github.workspace }}/Source/Properties/AssemblyInfo.cs
tag: ${{ github.event.release.tag_name }}

- name: Build mod solution
run: msbuild ${{ github.workspace }}/Source/KSCSwitcher.sln /t:build /restore /p:RestorePackagesConfig=true /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" /p:KSPRoot="${{ env.KSP_ROOT }}"

- name: Remove excess DLLs
uses: KSP-RO/BuildTools/remove-excess-dlls@master
with:
path: ${{ github.workspace }}/GameData/

- name: Update version file
uses: KSP-RO/BuildTools/update-version-file@master
with:
tag: ${{ github.event.release.tag_name }}
path: ${{ github.workspace }}/GameData/KSCSwitcher/KSCSwitcher.version

- name: Update Readme
uses: KSP-RO/BuildTools/update-version-in-readme@master
with:
path: ${{ github.workspace }}/README.md
tag: ${{ github.event.release.tag_name }}

- name: Update changelog file
uses: KSP-RO/BuildTools/process-changelog@master
with:
tag: ${{ github.event.release.tag_name }}
body: ${{ github.event.release.body }}
path: ${{ github.workspace }}/GameData/KSCSwitcher/changelog.cfg

- name: Assemble release
id: assemble-release
run: |
RELEASE_DIR="${RUNNER_TEMP}/release"
echo "Release dir: ${RELEASE_DIR}"
echo "Release zip: ${RELEASE_DIR}/KSCSwitcher-${{ github.event.release.tag_name }}.zip"
mkdir -v "${RELEASE_DIR}"
echo "::set-output name=release-dir::${RELEASE_DIR}"
cp -v -R "${{ github.workspace }}/GameData" "${RELEASE_DIR}"
cd ${RELEASE_DIR}
zip -r KSCSwitcher-${{ github.event.release.tag_name }}.zip GameData

- name: Upload package to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ steps.assemble-release.outputs.release-dir }}/KSCSwitcher-${{ github.event.release.tag_name }}.zip
asset_name: KSCSwitcher-${{ github.event.release.tag_name }}.zip
asset_content_type: application/zip

- name: Setup git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"

- name: Commit changes
shell: bash
env:
TAG_STRING: ${{ github.event.release.tag_name }}
run: |
RELEASEBRANCH=${{ env.tagged_branch }}
git add "${{ github.workspace }}/GameData/KSCSwitcher/KSCSwitcher.version"
git add "${{ github.workspace }}/GameData/KSCSwitcher/changelog.cfg"
git commit -m "Update version to $TAG_STRING"
git push origin $RELEASEBRANCH
git tag $TAG_STRING $RELEASEBRANCH --force
git push origin $TAG_STRING --force
75 changes: 75 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This is a basic workflow to help you get started with Actions

name: build

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
KSP_ROOT: /tmp/ksp

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check-secret:
uses: KSP-RO/BuildTools/.github/workflows/check-secret.yml@master
secrets:
KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }}

validate-cfg-files:
uses: KSP-RO/BuildTools/.github/workflows/validate-cfg-files.yml@master

build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [check-secret]
if: needs.check-secret.outputs.has-password == 'true'
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 100

- name: Download required assemblies
id: download-assemblies
uses: KSP-RO/BuildTools/download-assemblies-v2@master
with:
KSP_ZIP_PASSWORD: ${{ secrets.KSP_ZIP_PASSWORD }}

- name: Update AssemblyInfo
uses: KSP-RO/BuildTools/update-assembly-info@master
with:
path: ${{ github.workspace }}/Source/Properties/AssemblyInfo.cs
tag: "2.99.0.0"

- name: Build mod solution
run: msbuild ${{ github.workspace }}/Source/KSCSwitcher.sln /t:build /restore /p:RestorePackagesConfig=true /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" /p:KSPRoot="${{ env.KSP_ROOT }}"

- name: Remove excess DLLs
uses: KSP-RO/BuildTools/remove-excess-dlls@master
with:
path: ${{ github.workspace }}/GameData/

- name: Assemble release
id: assemble-release
run: |
RELEASE_DIR="${RUNNER_TEMP}/release"
echo "Release dir: ${RELEASE_DIR}"
mkdir -v "${RELEASE_DIR}"
echo "::set-output name=release-dir::${RELEASE_DIR}"
cp -v -R "${{ github.workspace }}/GameData" "${RELEASE_DIR}"

- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: KSCSwitcher
path: ${{ steps.assemble-release.outputs.release-dir }}
61 changes: 61 additions & 0 deletions .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Comment on pull request
on:
workflow_run:
workflows: ['build']
types: [completed]
jobs:
pr_comment:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v5
with:
# This snippet is public-domain, taken from
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
script: |
async function upsertComment(owner, repo, issue_number, purpose, body) {
const {data: comments} = await github.rest.issues.listComments(
{owner, repo, issue_number});

const marker = `<!-- bot: ${purpose} -->`;
body = marker + "\n" + body;

const existing = comments.filter((c) => c.body.includes(marker));
if (existing.length > 0) {
const last = existing[existing.length - 1];
core.info(`Updating comment ${last.id}`);
await github.rest.issues.updateComment({
owner, repo,
body,
comment_id: last.id,
});
} else {
core.info(`Creating a comment in issue / PR #${issue_number}`);
await github.rest.issues.createComment({issue_number, body, owner, repo});
}
}

const {owner, repo} = context.repo;
const run_id = ${{github.event.workflow_run.id}};

const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }};
if (!pull_requests.length) {
return core.error("This workflow doesn't match any pull requests!");
}

const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
if (!artifacts.length) {
return core.error(`No artifacts found`);
}
let body = `Download the artifacts for this pull request:\n`;
for (const art of artifacts) {
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
}

core.info("Review thread message body:", body);

for (const pr of pull_requests) {
await upsertComment(owner, repo, pr.number,
"nightly-link", body);
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Ignore all generated DLLs
*.dll

# User-specific files
*.rsuser
*.suo
Expand Down
Binary file removed GameData/KSCSwitcher/Plugins/KSCSwitcher.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions GameData/KSCSwitcher/changelog.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
KERBALCHANGELOG
{
modName = KSCSwitcher
license = BSD-2-Clause
author = KSP-RO team
website = github.com/KSP-RO/KSCSwitcher
}
29 changes: 19 additions & 10 deletions Source/KSCSwitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,36 @@
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/Assembly-CSharp.dll">
<HintPath>$(ReferencePath)/Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/System.dll">
<HintPath>$(ReferencePath)/System.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/System.Core.dll">
<HintPath>$(ReferencePath)/System.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/UnityEngine.dll">
<HintPath>$(ReferencePath)/UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/UnityEngine.CoreModule.dll">
<HintPath>$(ReferencePath)/UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\KSP DLL\UnityEngine.ImageConversionModule.dll</HintPath>
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/UnityEngine.ImageConversionModule.dll">
<HintPath>$(ReferencePath)/UnityEngine.ImageConversionModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.IMGUIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/UnityEngine.IMGUIModule.dll">
<HintPath>$(ReferencePath)/UnityEngine.IMGUIModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="$(KSPRoot)/KSP_x64_Data/Managed/UnityEngine.TextRenderingModule.dll">
<HintPath>$(ReferencePath)/UnityEngine.TextRenderingModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down
13 changes: 8 additions & 5 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define CIBUILD_disabled
using System.Reflection;
using System.Runtime.CompilerServices;

Expand All @@ -15,8 +16,10 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("2.0.0.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

#if CIBUILD
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
[assembly: KSPAssembly("KSCSwitcher", @MAJOR@, @MINOR@)]
#else
[assembly: AssemblyFileVersion("2.99.0.0")]
[assembly: KSPAssembly("KSCSwitcher", 2, 99)]
#endif
Loading