Skip to content
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
23 changes: 23 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
changelog:
exclude:
labels:
- ignore-for-release
authors:
- dependabot
categories:
- title: Features
labels:
- enhancement
- feature
- title: Bug Fixes
labels:
- bug
- fix
- title: Maintenance
labels:
- chore
- dependencies
- documentation
- title: Other Changes
labels:
- "*"
81 changes: 71 additions & 10 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
id: get_latest
uses: actions/github-script@v7.0.1
with:
result-encoding: string
script: |
let tag_name;
try {
Expand All @@ -48,6 +49,7 @@ jobs:

- name: Bump version and push tag
id: create_tag
if: github.event_name == 'push'
uses: anothrNick/github-tag-action@1.64.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -57,8 +59,13 @@ jobs:

- name: Check if version changed
id: check_version
env:
NEW_TAG: ${{ steps.create_tag.outputs.new_tag }}
LATEST_TAG: ${{ steps.get_latest.outputs.result }}
run: |
if [ "${{ steps.create_tag.outputs.new_tag }}" != ${{ steps.get_latest.outputs.result }} ]; then
new_version="${NEW_TAG#v}"
latest_version="${LATEST_TAG#v}"
if [ -n "$new_version" ] && [ "$new_version" != "$latest_version" ]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "version_changed=false" >> $GITHUB_OUTPUT
Expand All @@ -68,21 +75,32 @@ jobs:
if: needs.version.outputs.version_changed == 'true'
needs: version
permissions:
contents: write
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '10.0.x'

- name: Pack
run: dotnet pack -o nupkgs /p:PackageVersion=${{ needs.version.outputs.new_tag }}
env:
NEW_TAG: ${{ needs.version.outputs.new_tag }}
run: dotnet pack -o nupkgs -p:PackageVersion="$NEW_TAG"

- name: NuGet login
id: login
uses: NuGet/login@v1
with:
user: Delfram

- name: Push to NuGet
run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
run: dotnet nuget push nupkgs/*.nupkg --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate

release:
needs: [version, pack]
Expand All @@ -92,14 +110,57 @@ jobs:
steps:
- name: Create release
uses: actions/github-script@v7.0.1
env:
NEW_TAG: ${{ needs.version.outputs.new_tag }}
with:
script: |
const tag = process.env.NEW_TAG;
const version = tag.replace(/^v/, '');
const { owner, repo } = context.repo;

const notes = await github.rest.repos.generateReleaseNotes({
owner,
repo,
tag_name: tag
});

let body = notes.data.body;

// generate-notes lists merged pull requests only - fall back to plain commits when there are none
if (!/^\* /m.test(body)) {
const releases = await github.rest.repos.listReleases({ owner, repo, per_page: 1 });
const previousTag = releases.data[0]?.tag_name;

if (previousTag) {
const compare = await github.rest.repos.compareCommitsWithBasehead({
owner,
repo,
basehead: `${previousTag}...${tag}`
});

const lines = compare.data.commits.map((c) => {
const subject = c.commit.message.split('\n')[0];
const author = c.author?.login ?? c.commit.author.name;
return `* ${subject} by @${author} ([${c.sha.slice(0, 7)}](${c.html_url}))`;
});

if (lines.length > 0) {
body = `## What's Changed\n${lines.join('\n')}\n\n${body}`;
}
}
}

body = body.replace(
/\*\*Full Changelog\*\*: (\S+\/compare\/(\S+))/,
'**Full Changelog**: [$2]($1)'
);

const releaseResponse = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ needs.version.outputs.new_tag }}',
name: '[${{ needs.version.outputs.new_tag }}] CSSharpTemplates',
body: 'Changes in this Release',
owner,
repo,
tag_name: tag,
name: `v${version}`,
body: body,
draft: false,
prerelease: false
});
Expand Down
5 changes: 3 additions & 2 deletions CSSharpTemplates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<PackageIcon>icon.png</PackageIcon>
<Authors>Delfram</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>A comprehensive set of CounterStrikeSharp templates for creating Counter-Strike 2 plugins. These templates provide base structures, utility functions, and best practices to kickstart your CounterStrikeSharp plugin development. Ideal for both beginners and experienced developers.</Description>
<Description>Project templates for CounterStrikeSharp plugins: a ready-made project structure, a VS Code build task and an optional GitHub workflow with automatic versioning and releases.</Description>
<PackageTags>counterstrikesharp;cs2plugin;cs2;cssharp</PackageTags>
<PackageProjectUrl>https://github.com/Delfram99/CounterStrikeSharpTemplates</PackageProjectUrl>
<RepositoryUrl>https://github.com/Delfram99/CounterStrikeSharpTemplates.git</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageType>Template</PackageType>
<NoWarn>$(NoWarn);NU5128</NoWarn>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IncludeBuildOutput>false</IncludeBuildOutput>
<NoDefaultExcludes>true</NoDefaultExcludes>
<NoBuild>true</NoBuild>
Expand All @@ -24,6 +24,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="**/*" />
<content Include="content/**/*" Exclude="content/templates/**/bin/**;content/templates/**/obj/**">
<PackagePath>content/</PackagePath>
</content>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Alex Vilyus
Copyright (c) 2026 Delfram99

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
81 changes: 36 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

## Description

CounterStrikeSharpTemplates is a thoughtfully designed template set for kick-starting your plugin development for the great [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp). The templates offer foundational structures and useful functions, along with pre-configured GitHub workflows, making the initiation of plugin development a breeze. With adaptable templates and an automated version control system, it caters to both beginners and experienced developers alike.
Project templates for [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp) plugins: a ready-made project structure, a VS Code build task and an optional GitHub workflow with automatic versioning and releases.

## Installation

1. Install the [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0).
1. Install the [.NET 10.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/10.0).
2. Install the templates package:

```bash
Expand All @@ -18,80 +18,77 @@ dotnet new install CounterStrikeSharpTemplates

## Usage

Currently available templates:

- `default`: сreates a basic plugin template.
- `config`: сreates a plugin template that includes a configuration.
- `lang`: сreates a plugin template that includes a language.
- `configlang`: сreates a plugin template that includes both a configuration and a language.
- `datamysql`: сreates a plugin template that includes a database (MySQL), language, configuration, and commands.

[You can also add your own templates](#adding-your-own-template).

To specify a template type, use `--t`:

```bash
dotnet new cssharp -n MyPlugin --t config
dotnet new cssharp -n MyPlugin
```

To create a new basic project (using the `default` template), just:
### Templates (`--t`)

```bash
dotnet new cssharp -n MyPlugin
```
| Template | Contents |
| --- | --- |
| `default` | basic plugin, used when `--t` is omitted |
| `config` | + JSON configuration |
| `lang` | + translations and commands |
| `configlang` | + configuration, translations and commands |
| `datamysql` | + MySQL database, configuration, translations and commands |

For GitHub integration (which provides GitHub workflows, .gitignore, etc.), add `--g`:
[You can also add your own templates](#adding-your-own-template).

```bash
dotnet new cssharp -n MyPlugin --g
```
### Options

Customize with `--np` (plugin name) and `--ap` (author):
| Option | Description |
| --- | --- |
| `--t` | template type (see the table above) |
| `--g` | add GitHub files: build & release workflow, release notes config, `.gitignore` |
| `--np` | plugin name used in code (default `MyPlugin`) |
| `--ap` | author name (default `AuthorName`) |
| `--skipRestore` | do not run `dotnet restore` after the project is created |

```bash
dotnet new cssharp -n MyPlugin --t datamysql --g --np "My Plugin" --ap "Author Name"
```

## Local Compilation

For local compilation in Visual Studio Code, you can use the hotkey `Ctrl + Shift + B`. This will trigger the build task defined in the `tasks.json` file.

To have the plugin compiled directly into your server folder, replace the line in the `.vscode/tasks.json` file:
`Ctrl + Shift + B` in Visual Studio Code runs the build task from `.vscode/tasks.json`. To compile the plugin straight into your server folder, replace the output path in that file:

```json
"compiled/CSSharpTemplates"
```

with your own path, for example:
with your own, for example:

```json
"D:/cs2-server/game/csgo/addons/counterstrikesharp/plugins/CSSharpTemplates"
```

## Versioning

Push commit messages with `#major`, `#minor`, or `#patch` to update the plugin's version (when `--g` is used):
Available when the project is created with `--g`. The version is bumped by a keyword in the commit message:

```bash
git commit -m "add new feature #minor"
```

For manual version specification, use the `workflow_dispatch` option in the GitHub Actions tab.
`#major` → `2.0.0`, `#minor` → `1.1.0`, `#patch` → `1.0.1`. A version can also be set manually through `Run workflow` on the Actions tab.

The workflow builds the plugin, creates a release with automatically generated notes and attaches the zip archive. It only starts when source files change - editing the README does not trigger a build.

## Environment Variables

In `dotnet.yml`, modify these variables as needed:

- `PLUGIN_NAME`: your plugin's name (please do not use spaces).
- `DOTNET_VERSION`: .NET version (default is `8.0.x`).
- `PATH_PLUGIN`: plugin path (default is `addons/counterstrikesharp/plugins/`).
- `START_VERSION`: starting version (default is `1.0.0`).
- `USE_V_VERSION`: prefix the version number with a 'v' (default is `true`).
| Variable | Default | Description |
| --- | --- | --- |
| `PLUGIN_NAME` | plugin name | used for the archive and the folder inside it, do not use spaces |
| `DOTNET_VERSION` | `10.0.x` | .NET SDK version used to build |
| `TARGET_FRAMEWORK` | `net10.0` | must match `TargetFramework` in the `.csproj` |
| `PATH_PLUGIN` | `addons/counterstrikesharp/plugins/` | plugin path inside the archive |
| `START_VERSION` | `1.0.0` | version used for the first release |
| `USE_V_VERSION` | `true` | prefix the version number with a `v` |

## Adding Your Own Template

To add your own template, follow these steps:

1. Clone the repository:

```bash
Expand Down Expand Up @@ -131,15 +128,9 @@ To add your own template, follow these steps:
dotnet new install . --force
```

## Conclusion

In the future, additional templates will be added as needed. If you have any ideas on how to improve or modify these templates to make plugin development even easier, please let me know.

Feel free to open an issue or submit a pull request if you have any suggestions or find any problems. Your feedback is always welcome!

## Contact
## Contributing

If you have any questions or suggestions, feel free to contact me on Discord: `delfram`.
New templates are added as needed. If you have an idea, found a problem or want to improve something - open an issue or a pull request, feedback is always welcome.

## Credits

Expand Down
30 changes: 27 additions & 3 deletions content/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/template",
"$schema": "https://json.schemastore.org/template",
"author": "Delfram",
"classifications": [
"CounterStrikeSharp",
Expand All @@ -12,8 +12,8 @@
],
"name": "CounterStrikeSharpTemplates",
"groupIdentity": "com.plugin.CounterStrikeSharp",
"identity": "com.plugin.CounterStrikeSharp.Template.1.0.0",
"description": "This is a collection templates specifically designed for creating plugins for the Runtime Assembly CounterStrikeSharp. It includes foundational structures and utility functions to expedite your CounterStrikeSharp plugin development.",
"identity": "com.plugin.CounterStrikeSharp.Template",
"description": "Project templates for CounterStrikeSharp plugins: a ready-made project structure, a VS Code build task and an optional GitHub workflow with automatic versioning and releases.",
"shortName": "cssharp",
"sourceName": "CSSharpTemplates",
"tags": {
Expand Down Expand Up @@ -67,6 +67,12 @@
],
"defaultValue": "default",
"description": "Choose the type of template for your project based on the features you need."
},
"skipRestore": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Skips the automatic restore of the project after creation."
}
},
"sources": [
Expand Down Expand Up @@ -104,5 +110,23 @@
"target": "./",
"condition": "(t == 'datamysql')"
}
],
"primaryOutputs": [
{
"path": "CSSharpTemplates.csproj"
}
],
"postActions": [
{
"condition": "(!skipRestore)",
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [
{
"text": "Run 'dotnet restore'"
}
],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
}
]
}
Loading
Loading