Skip to content

Commit

Permalink
Add GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Nov 11, 2022
1 parent 26a711a commit b8986bb
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 2 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/attachReleaseArtifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: "Attach Release Artifacts"

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

# 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@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
shell: bash
env:
TAG_STRING: ${{ github.event.release.tag_name }}
run: |
rm -f ${GITHUB_WORKSPACE}/GameData/ROHeatshields/Plugins/*.dll
msbuild /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" ${GITHUB_WORKSPACE}/Source/ROHeatshields.sln
cp -v ${GITHUB_WORKSPACE}/Source/obj/x64/Release/ROHeatshields.dll ${GITHUB_WORKSPACE}/GameData/ROHeatshields/Plugins/ROHeatshields.dll
- name: Update version file
uses: KSP-RO/BuildTools/update-version-file@master
with:
tag: ${{ github.event.release.tag_name }}
path: ${GITHUB_WORKSPACE}/GameData/ROHeatshields/ROHeatshields.version

- name: Assemble release
id: assemble-release
run: |
RELEASE_DIR="${RUNNER_TEMP}/release"
echo "Release dir: ${RELEASE_DIR}"
echo "Release zip: ${RELEASE_DIR}/ROHeatshields-${{ 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}"
cp -v "${GITHUB_WORKSPACE}/README.md" "${RELEASE_DIR}/README.md"
cp -v "${GITHUB_WORKSPACE}/LICENSE" "${RELEASE_DIR}/LICENSE"
cd ${RELEASE_DIR}
zip -r ROHeatshields-${{ github.event.release.tag_name }}.zip GameData README.md LICENSE
- 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 }}/ROHeatshields-${{ github.event.release.tag_name }}.zip
asset_name: ROHeatshields-${{ 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 new version file
shell: bash
env:
TAG_STRING: ${{ github.event.release.tag_name }}
run: |
RELEASEBRANCH=${{ env.tagged_branch }}
git add "${GITHUB_WORKSPACE}/GameData/ROHeatshields/ROHeatshields.version"
git commit -m "Update version to $TAG_STRING"
git push origin $RELEASEBRANCH
git tag $TAG_STRING $RELEASEBRANCH --force
git push origin $TAG_STRING --force
65 changes: 65 additions & 0 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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, CI ]
pull_request:
branches: [ master, CI ]

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

# 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:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 100

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

- name: Build mod solution
run: |
rm -f ${GITHUB_WORKSPACE}/GameData/ROHeatshields/Plugins/*.dll
msbuild /p:Configuration=Release /p:ReferencePath="${{ steps.download-assemblies.outputs.ksp-dll-path }}" ${GITHUB_WORKSPACE}/Source/ROHeatshields.sln
cp -v ${GITHUB_WORKSPACE}/Source/obj/x64/Release/ROHeatshields.dll ${GITHUB_WORKSPACE}/GameData/ROHeatshields/Plugins/ROHeatshields.dll
- 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}"
cp -v "${GITHUB_WORKSPACE}/README.md" "${RELEASE_DIR}/README.md"
cp -v "${GITHUB_WORKSPACE}/LICENSE" "${RELEASE_DIR}/LICENSE"
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: ROHeatshields
path: ${{ steps.assemble-release.outputs.release-dir }}
Binary file removed GameData/ROHeatshields/Plugins/ROHeatshields.dll
Binary file not shown.
7 changes: 6 additions & 1 deletion Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
#define CIBUILD_disabled
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -33,4 +34,8 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
#if CIBUILD
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
#else
[assembly: AssemblyFileVersion("1.1.0.0")]
#endif
2 changes: 1 addition & 1 deletion Source/ROHeatshields.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<OutputPath>..\GameData\ROHeatshields\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<DebugType>none</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>8.0</LangVersion>
<ErrorReport>prompt</ErrorReport>
Expand Down

0 comments on commit b8986bb

Please sign in to comment.