Skip to content

Commit

Permalink
improvement: refactoring for automatic build of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalle Minkner committed Nov 11, 2024
1 parent d0f3a93 commit 8a1a758
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 137 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Build Release

env:
REPOSITORY_FOLDER: "src" # subfolder with source code
PLUGIN_NAME: "LuckyDefuse" # main file of the project

on:
push:
branches:
- main
paths:
- 'src/Version.cs' # only on change of the file with the version number string in it
workflow_dispatch:

# job to create a new release
jobs:
create-release:
runs-on: ubuntu-latest

steps:
- name: Get Repository Name
run: echo "REPOSITORY_NAME=`basename ${{ github.repository }}`" >> $GITHUB_ENV

- name: Checkout Repository
uses: actions/checkout@v2

- name: Get Current Project Version Number From Version.cs
id: get_version
run: |
version=$(grep -oP '(?<=ModuleVersion => ")[^"]*' ${{ env.REPOSITORY_FOLDER }}/Version.cs)
echo "version=$version" >> $GITHUB_ENV
- name: Get Current Release Version Number
id: get_latest_release
run: |
latest_release=$(curl -s -H "Authorization: token ${{ secrets.UPLOAD_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "latest_release=$latest_release" >> $GITHUB_ENV
- name: Compare Versions
id: compare_versions
run: |
if [ "${{ env.version }}" != "${{ env.latest_release }}" ]; then
echo "new_version=true" >> $GITHUB_ENV
else
echo "new_version=false" >> $GITHUB_ENV
fi
- name: Install .NET
uses: actions/setup-dotnet@v2
if: env.new_version == 'true'
with:
dotnet-version: '8.0.x'

- name: Install Dependencies
if: env.new_version == 'true'
run: dotnet restore

- name: Build ${{ env.REPOSITORY_NAME }}
if: env.new_version == 'true'
run: dotnet publish -c Release

- name: Prepare ${{ env.REPOSITORY_NAME }}.info
if: env.new_version == 'true'
run: |
echo "version: ${{ env.version }}" > /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/publish/${{ env.PLUGIN_NAME }}.info
echo "repository: https://github.com/${{ github.repository }}" >> /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/publish/${{ env.PLUGIN_NAME }}.info
- name: Prepare Release
if: env.new_version == 'true'
run: |
mv /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/publish/ /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/${{ env.PLUGIN_NAME }}/
- name: Compress Release
if: env.new_version == 'true'
run: cd /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0 && zip -r /home/runner/work/${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip ${{ env.PLUGIN_NAME }}

- name: Build Release Notes
if: env.new_version == 'true'
id: get_release_notes
run: |
release_notes=$(git log --pretty=format:"[%h](https://github.com/${{ github.repository }}/commit/%H) - %s (%an)" $(git describe --tags --abbrev=0)..HEAD)
echo "release_notes=$release_notes" >> $GITHUB_ENV
- name: Add Release on Github
id: create_release
if: env.new_version == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }}
with:
tag_name: ${{ env.version }}
release_name: ${{ env.version }}
body: ${{ env.release_notes }}
draft: false
prerelease: false

- name: Upload ${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip
if: env.new_version == 'true'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: /home/runner/work/${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip
asset_name: ${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip
asset_content_type: application/zip
131 changes: 0 additions & 131 deletions LuckyDefusePlugin.cs.bkp

This file was deleted.

2 changes: 1 addition & 1 deletion LuckyDefusePlugin.sln → cs2-lucky-defuse.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuckyDefusePlugin", "LuckyDefusePlugin.csproj", "{1DA5A1A0-3AA7-42AC-9BDC-4DB15531869D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuckyDefuse", "src/LuckyDefuse.csproj", "{1DA5A1A0-3AA7-42AC-9BDC-4DB15531869D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
7 changes: 3 additions & 4 deletions LuckyDefusePlugin.cs → src/LuckyDefuse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Utils;

namespace LuckyDefusePlugin;
namespace LuckyDefuse;

public class PluginConfig : BasePluginConfig
{
Expand All @@ -19,11 +19,10 @@ public class PluginConfig : BasePluginConfig
public int NotificationDelay { get; set; } = 30;
}

public class LuckyDefusePlugin : BasePlugin, IPluginConfig<PluginConfig>
public partial class LuckyDefuse : BasePlugin, IPluginConfig<PluginConfig>
{
public override string ModuleName => "Lucky Defuse Plugin";
public override string ModuleAuthor => "Jon-Mailes Graeffe <[email protected]>";
public override string ModuleVersion => "1.0.1";

public PluginConfig Config { get; set; } = null!;

Expand All @@ -43,7 +42,7 @@ public class LuckyDefusePlugin : BasePlugin, IPluginConfig<PluginConfig>
private bool _wireChosenManually;
private bool _roundEnded;

public LuckyDefusePlugin()
public LuckyDefuse()
{
var options = new string[_colors.Length];
for (int i = 0; i < _colors.Length; ++i)
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/Version.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LuckyDefuse;

public partial class LuckyDefuse
{
public override string ModuleVersion => "1.0.1";
}
2 changes: 1 addition & 1 deletion WireMenu.cs → src/WireMenu.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;

namespace LuckyDefusePlugin;
namespace LuckyDefuse;

public class WireMenu(BasePlugin plugin, string title, string[] options)
{
Expand Down
File renamed without changes.

0 comments on commit 8a1a758

Please sign in to comment.