Skip to content

Commit

Permalink
INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed May 13, 2024
0 parents commit 7f12a0f
Show file tree
Hide file tree
Showing 17 changed files with 714 additions and 0 deletions.
193 changes: 193 additions & 0 deletions Core/.github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
name: Build & Release

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
PluginVersion:
description: 'Plugin Version'
required: true
default: 'v1.0.0'

env:
PLUGIN_NAME: Core
DOTNET_VERSION: 8.0.x
PATH_PLUGIN: addons/counterstrikesharp/plugins/
START_VERSION: 1.0.0
USE_V_VERSION: true

jobs:
version:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.determine_new_tag.outputs.result }}
no_release: ${{ steps.check_release.outputs.result }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'

- name: Check if tag exists
if: github.event_name == 'workflow_dispatch'
id: check_tag
run: |
if git fetch --tags && git tag -l | grep -q "^${{ github.event.inputs.PluginVersion }}$"; then
echo "Tag ${{ github.event.inputs.PluginVersion }} already exists."
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "Tag ${{ github.event.inputs.PluginVersion }} does not exist."
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Set custom tag and push to repository
if: github.event_name == 'workflow_dispatch' && steps.check_tag.outputs.tag_exists == 'false'
id: set_custom_tag
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git tag ${{ github.event.inputs.PluginVersion }}
git push origin ${{ github.event.inputs.PluginVersion }}
shell: bash

- name: Bump version and push tag
if: github.event_name != 'workflow_dispatch'
id: create_tag
uses: anothrNick/github-tag-action@1.64.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: ${{ env.USE_V_VERSION }}
DEFAULT_BUMP: none
INITIAL_VERSION: ${{ env.START_VERSION }}

- name: Determine New Tag
id: determine_new_tag
uses: actions/github-script@v7.0.1
with:
script: |
const customTag = "${{ github.event.inputs.PluginVersion }}";
const createdTag = "${{ steps.create_tag.outputs.new_tag }}";
const newTag = customTag ? customTag : createdTag;
console.log(`New tag determined: ${newTag}`);
return newTag;
- name: Check if release exists
id: check_release
uses: actions/github-script@v7.0.1
with:
script: |
let release_exists;
try {
const response = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: ${{ steps.determine_new_tag.outputs.result }}
});
console.log(`Release found for tag: ${response.data.tag_name}`);
release_exists = true;
} catch (error) {
if (error.status === 404) {
console.log("No release found for this tag.");
release_exists = false;
} else {
throw error;
}
}
return release_exists;
build:
if: needs.version.outputs.no_release == 'false'
needs: version
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Update version
run: find . -type f -name '*.cs' -exec sed -i 's/public override string ModuleVersion =>.*/public override string ModuleVersion => ${{ needs.version.outputs.new_tag }};/g' {} \;

- name: Build
run: dotnet build -c Release

- name: Create plugin directory
run: |
mkdir -p plugin/${{ env.PATH_PLUGIN }}${{ env.PLUGIN_NAME }}
rm -rf ./bin/Release/net8.0/*.pdb
rm -rf ./bin/Release/net8.0/*.deps.json
cp -r ./bin/Release/net8.0/* plugin/${{ env.PATH_PLUGIN }}${{ env.PLUGIN_NAME }}
- name: Zip plugin
run: |
cd plugin/
zip -r ${{ env.PLUGIN_NAME }}-${{ github.sha }}.zip .
- name: Publish
uses: actions/upload-artifact@v4
with:
name: ${{ env.PLUGIN_NAME }}-${{ github.sha }}
path: plugin

release:
needs: [version, build]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.PLUGIN_NAME }}-${{ github.sha }}
path: plugin

- name: Create release
id: create_release
uses: actions/github-script@v7.0.1
with:
script: |
const tag_name = ${{ needs.version.outputs.new_tag }}.replace(/\"/g, '');
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag_name,
name: `[${tag_name}] ${{ env.PLUGIN_NAME }}`,
body: "Changes in this Release",
draft: false,
prerelease: false
});
return release.data.id;
- name: Upload release asset
id: upload-release-asset
uses: actions/github-script@v7.0.1
with:
script: |
const fs = require('fs');
const assetPath = `./plugin/${{ env.PLUGIN_NAME }}-${{ github.sha }}.zip`;
const assetName = `${{ env.PLUGIN_NAME }}-${{ needs.version.outputs.new_tag }}.zip`;
const asset = fs.readFileSync(assetPath);
const response = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.create_release.outputs.result }},
name: assetName,
data: asset,
headers: {
'content-type': 'application/zip',
'content-length': asset.length
}
});
console.log(`Asset uploaded: ${response.data.browser_download_url}`);
5 changes: 5 additions & 0 deletions Core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/
obj/
compiled/
*.sln
.vs/
21 changes: 21 additions & 0 deletions Core/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Core.csproj",
"--output",
"compiled/Core",
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
26 changes: 26 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CounterStrikeSharp.API.Core;
using System.Text.Json.Serialization;

namespace Core
{
public class CoreConfig : BasePluginConfig
{
public override int Version { get; set; } = 1;

[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "";

[JsonPropertyName("DatabasePort")]
public int DatabasePort { get; set; } = 3036;

[JsonPropertyName("DatabaseUser")]
public string DatabaseUser { get; set; } = "";

[JsonPropertyName("DatabasePassword")]
public string DatabasePassword { get; set; } = "";

[JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "";

}
}
57 changes: 57 additions & 0 deletions Core/Core.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Commands;
using Microsoft.Extensions.Logging;

namespace Core;

// [MinimumApiVersion(160)]
public partial class Core : BasePlugin, IPluginConfig<CoreConfig>
{
public CoreConfig Config { get; set; } = new();
internal static DataBaseService? _dataBaseService;

public override string ModuleName => "Core";
public override string ModuleDescription => "";
public override string ModuleAuthor => "Oscar Wos-Szlaga";
public override string ModuleVersion => "0.0.1";


public void OnConfigParsed(CoreConfig config)
{
/*
_dataBaseService = new DataBaseService(config);
_dataBaseService.TestAndCheckDataBaseTableAsync().GetAwaiter().GetResult();
Config = config;
*/
}


public override void Load(bool hotReload)
{
}

[ConsoleCommand("css_hello", "Say hello in the player language")]
public void OnCommandHello(CCSPlayerController? player, CommandInfo command)
{
/*
if (player != null)
{
string playerName = player.PlayerName;
var playerLanguage = player.GetLanguage();
ulong playerSteamId = player.SteamID;
string commandString = command.GetArg(0).ToLower();
_ = CheckPlayerCommand(commandString, playerName, playerSteamId);
}
*/
if (player != null)
command.ReplyToCommand($"{Localizer["hello.player", player.PlayerName, player.GetLanguage()]}");
}
}
20 changes: 20 additions & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="MySqlConnector" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Loading

0 comments on commit 7f12a0f

Please sign in to comment.