diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..8e51713 --- /dev/null +++ b/.github/release.yml @@ -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: + - "*" diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e80a7a7..a411512 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -28,6 +28,7 @@ jobs: id: get_latest uses: actions/github-script@v7.0.1 with: + result-encoding: string script: | let tag_name; try { @@ -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 }} @@ -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 @@ -68,7 +75,8 @@ 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 @@ -76,13 +84,23 @@ jobs: - 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] @@ -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 }); diff --git a/CSSharpTemplates.csproj b/CSSharpTemplates.csproj index 3a6559a..3d6d077 100644 --- a/CSSharpTemplates.csproj +++ b/CSSharpTemplates.csproj @@ -7,14 +7,14 @@ icon.png Delfram MIT - 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. + 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. counterstrikesharp;cs2plugin;cs2;cssharp https://github.com/Delfram99/CounterStrikeSharpTemplates https://github.com/Delfram99/CounterStrikeSharpTemplates.git README.md Template $(NoWarn);NU5128 - net8.0 + net10.0 false true true @@ -24,6 +24,7 @@ + content/ diff --git a/LICENSE b/LICENSE index b1e9209..6ac5ae4 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index b440d90..969fcda 100644 --- a/README.md +++ b/README.md @@ -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 @@ -18,35 +18,31 @@ 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" @@ -54,15 +50,13 @@ dotnet new cssharp -n MyPlugin --t datamysql --g --np "My Plugin" --ap "Author N ## 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" @@ -70,28 +64,31 @@ with your own path, for example: ## 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 @@ -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 diff --git a/content/.template.config/template.json b/content/.template.config/template.json index 4927bba..60c191a 100644 --- a/content/.template.config/template.json +++ b/content/.template.config/template.json @@ -1,5 +1,5 @@ { - "$schema": "http://json.schemastore.org/template", + "$schema": "https://json.schemastore.org/template", "author": "Delfram", "classifications": [ "CounterStrikeSharp", @@ -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": { @@ -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": [ @@ -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 + } ] } \ No newline at end of file diff --git a/content/github/.github/release.yml b/content/github/.github/release.yml new file mode 100644 index 0000000..8e51713 --- /dev/null +++ b/content/github/.github/release.yml @@ -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: + - "*" diff --git a/content/github/.github/workflows/dotnet.yml b/content/github/.github/workflows/dotnet.yml index d53a2a6..7a7e169 100644 --- a/content/github/.github/workflows/dotnet.yml +++ b/content/github/.github/workflows/dotnet.yml @@ -3,8 +3,22 @@ name: Build & Release on: push: branches: [ "main" ] + paths: + - '**/*.cs' + - '**/*.csproj' + - '**/*.sln' + - '**/*.slnx' + - 'lang/**' + - '.github/workflows/dotnet.yml' pull_request: branches: [ "main" ] + paths: + - '**/*.cs' + - '**/*.csproj' + - '**/*.sln' + - '**/*.slnx' + - 'lang/**' + - '.github/workflows/dotnet.yml' workflow_dispatch: inputs: PluginVersion: @@ -14,7 +28,8 @@ on: env: PLUGIN_NAME: CSSharpTemplates - DOTNET_VERSION: 8.0.x + DOTNET_VERSION: 10.0.x + TARGET_FRAMEWORK: net10.0 PATH_PLUGIN: addons/counterstrikesharp/plugins/ START_VERSION: 1.0.0 USE_V_VERSION: true @@ -25,169 +40,161 @@ jobs: contents: write runs-on: ubuntu-latest outputs: - new_tag: ${{ steps.determine_new_tag.outputs.result }} - no_release: ${{ steps.check_release.outputs.result }} + new_tag: ${{ steps.determine_new_tag.outputs.new_tag }} + release_exists: ${{ steps.check_release.outputs.release_exists }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 with: fetch-depth: '0' - name: Check if tag exists if: github.event_name == 'workflow_dispatch' id: check_tag + env: + PLUGIN_VERSION: ${{ github.event.inputs.PluginVersion }} + shell: bash 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 + git fetch --tags --force + if git rev-parse -q --verify "refs/tags/$PLUGIN_VERSION" > /dev/null; then + echo "Tag $PLUGIN_VERSION already exists." + echo "tag_exists=true" >> "$GITHUB_OUTPUT" else - echo "Tag ${{ github.event.inputs.PluginVersion }} does not exist." - echo "tag_exists=false" >> $GITHUB_OUTPUT + echo "Tag $PLUGIN_VERSION 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 }} + env: + PLUGIN_VERSION: ${{ github.event.inputs.PluginVersion }} shell: bash + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + git tag "$PLUGIN_VERSION" + git push origin "refs/tags/$PLUGIN_VERSION" - name: Bump version and push tag - if: github.event_name != 'workflow_dispatch' + if: github.event_name == 'push' id: create_tag - uses: anothrNick/github-tag-action@1.64.0 + uses: anothrNick/github-tag-action@1.75.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 + - 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; + env: + CUSTOM_TAG: ${{ github.event.inputs.PluginVersion }} + CREATED_TAG: ${{ steps.create_tag.outputs.new_tag }} + shell: bash + run: | + new_tag="${CUSTOM_TAG:-$CREATED_TAG}" + echo "New tag determined: ${new_tag:-(none)}" + echo "new_tag=$new_tag" >> "$GITHUB_OUTPUT" - 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; + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + NEW_TAG: ${{ steps.determine_new_tag.outputs.new_tag }} + shell: bash + run: | + if [ -z "$NEW_TAG" ]; then + echo "No tag determined, nothing to release." + echo "release_exists=false" >> "$GITHUB_OUTPUT" + elif gh release view "$NEW_TAG" > /dev/null 2>&1; then + echo "Release for tag $NEW_TAG already exists." + echo "release_exists=true" >> "$GITHUB_OUTPUT" + else + echo "No release found for tag $NEW_TAG." + echo "release_exists=false" >> "$GITHUB_OUTPUT" + fi build: - if: needs.version.outputs.no_release == 'false' + if: needs.version.outputs.release_exists == 'false' needs: version permissions: - contents: write + contents: read runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v6 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' {} \; - + if: needs.version.outputs.new_tag != '' + env: + NEW_TAG: ${{ needs.version.outputs.new_tag }} + run: | + find . -type f -name '*.cs' -exec sed -i "s|public override string ModuleVersion =>.*|public override string ModuleVersion => \"${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 }} + mkdir -p "plugin/${PATH_PLUGIN}${PLUGIN_NAME}" + rm -f "./bin/Release/${TARGET_FRAMEWORK}"/*.pdb "./bin/Release/${TARGET_FRAMEWORK}"/*.deps.json + cp -r "./bin/Release/${TARGET_FRAMEWORK}"/* "plugin/${PATH_PLUGIN}${PLUGIN_NAME}" - name: Zip plugin run: | cd plugin/ - zip -r ${{ env.PLUGIN_NAME }}-${{ github.sha }}.zip . + zip -r "${PLUGIN_NAME}-${GITHUB_SHA}.zip" . - name: Publish - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: ${{ env.PLUGIN_NAME }}-${{ github.sha }} path: plugin release: + if: needs.version.outputs.new_tag != '' && github.event_name != 'pull_request' needs: [version, build] permissions: contents: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Download artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v8 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}`); \ No newline at end of file + - name: Create release and upload asset + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + NEW_TAG: ${{ needs.version.outputs.new_tag }} + shell: bash + run: | + version="${NEW_TAG#v}" + notes=$(gh api "repos/${GH_REPO}/releases/generate-notes" -f tag_name="$NEW_TAG" --jq .body) + + # generate-notes lists merged pull requests only - fall back to plain commits when there are none + if ! grep -q '^\* ' <<< "$notes"; then + prev_tag=$(gh release view --json tagName --jq .tagName 2>/dev/null || true) + if [ -n "$prev_tag" ]; then + commits=$(gh api "repos/${GH_REPO}/compare/${prev_tag}...${NEW_TAG}" \ + --jq '.commits[] | "* \(.commit.message | split("\n")[0]) by @\(.author.login // .commit.author.name) ([\(.sha[0:7])](\(.html_url)))"') + if [ -n "$commits" ]; then + notes=$(printf "## What's Changed\n%s\n\n%s" "$commits" "$notes") + fi + fi + fi + + notes=$(sed -E 's#\*\*Full Changelog\*\*: (https://[^[:space:]]+/compare/([^[:space:]]+))#**Full Changelog**: [\2](\1)#' <<< "$notes") + + gh release create "$NEW_TAG" \ + --title "v${version}" \ + --notes "$notes" \ + "./plugin/${PLUGIN_NAME}-${GITHUB_SHA}.zip#${PLUGIN_NAME}-${NEW_TAG}.zip" + echo "Release published: $(gh release view "$NEW_TAG" --json url --jq .url)" \ No newline at end of file diff --git a/content/github/README.md b/content/github/README.md index 04f0780..e8ea87d 100644 --- a/content/github/README.md +++ b/content/github/README.md @@ -92,13 +92,18 @@ This will trigger the workflow with the specified version, build your plugin, an In the `dotnet.yml` file, several environment variables are defined under the `env` section: - `PLUGIN_NAME`: The name of your plugin. -- `DOTNET_VERSION`: The version of .NET you are using in your project. Currently, it's set to `8.0`. +- `DOTNET_VERSION`: The version of the .NET SDK used to build the project. Currently, it's set to `10.0.x`. +- `TARGET_FRAMEWORK`: The target framework of your project, used to locate the build output. It must match the `TargetFramework` in your `.csproj` (currently `net10.0`). - `PATH_PLUGIN`: The path where your plugin is located. Here, it's `addons/counterstrikesharp/plugins/`. - `START_VERSION`: The starting version of your project. It's set to `1.0.0`. - `USE_V_VERSION`: A boolean value indicating whether to prefix the version number with a 'v'. If set to `true`, your version will look like `v1.0.0`. You can modify these variables according to your project's needs. +### When the Workflow Runs + +On `push` and `pull_request` the workflow only starts when source files change - `**/*.cs`, `**/*.csproj`, `**/*.sln`, `lang/**` or the workflow file itself. Editing the README, license or images does not trigger a build. The `Run workflow` button ignores this filter and always works. + ## Conclusion That's all you need to know about managing your plugin's version with GitHub. Remember, you can either push a commit with `#major`, `#minor`, or `#patch` in the message for automatic versioning, or manually set a version using `workflow_dispatch`. diff --git a/content/templates/config/CSSharpTemplates.csproj b/content/templates/config/CSSharpTemplates.csproj index f2b0cf6..a678ac3 100644 --- a/content/templates/config/CSSharpTemplates.csproj +++ b/content/templates/config/CSSharpTemplates.csproj @@ -1,14 +1,14 @@ - net8.0 + net10.0 enable enable true - + diff --git a/content/templates/configlang/CSSharpTemplates.csproj b/content/templates/configlang/CSSharpTemplates.csproj index d4b7e03..ee0057e 100644 --- a/content/templates/configlang/CSSharpTemplates.csproj +++ b/content/templates/configlang/CSSharpTemplates.csproj @@ -1,14 +1,14 @@ - net8.0 + net10.0 enable enable true - + diff --git a/content/templates/datamysql/CSSharpTemplates.csproj b/content/templates/datamysql/CSSharpTemplates.csproj index 678430e..e893d58 100644 --- a/content/templates/datamysql/CSSharpTemplates.csproj +++ b/content/templates/datamysql/CSSharpTemplates.csproj @@ -1,14 +1,14 @@ - net8.0 + net10.0 enable enable true - + diff --git a/content/templates/default/CSSharpTemplates.csproj b/content/templates/default/CSSharpTemplates.csproj index 27b3973..ae56a4e 100644 --- a/content/templates/default/CSSharpTemplates.csproj +++ b/content/templates/default/CSSharpTemplates.csproj @@ -1,14 +1,14 @@ - net8.0 + net10.0 enable enable true - + diff --git a/content/templates/lang/CSSharpTemplates.csproj b/content/templates/lang/CSSharpTemplates.csproj index d4b7e03..ee0057e 100644 --- a/content/templates/lang/CSSharpTemplates.csproj +++ b/content/templates/lang/CSSharpTemplates.csproj @@ -1,14 +1,14 @@ - net8.0 + net10.0 enable enable true - +