-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from oscar-wos/1.3.1
Refactor
- Loading branch information
Showing
31 changed files
with
537 additions
and
2,067 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,198 +1,90 @@ | ||
name: Build & Release | ||
name: Build and Release | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
workflow_dispatch: | ||
inputs: | ||
PluginVersion: | ||
description: 'Plugin Version' | ||
required: true | ||
default: '1.0.0' | ||
|
||
env: | ||
PLUGIN_NAME: Sessions | ||
DOTNET_VERSION: 8.0.x | ||
PATH_PLUGIN: addons/counterstrikesharp/ | ||
START_VERSION: 1.0.0 | ||
USE_V_VERSION: false | ||
push: | ||
branches: | ||
- main | ||
pull_request_review: | ||
types: | ||
- submitted | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
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' | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
- 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 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- 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: Setup .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- 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: Restore dependencies | ||
run: dotnet restore | ||
|
||
- 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; | ||
- name: Build | ||
run: dotnet build -c Release | ||
|
||
build: | ||
if: needs.version.outputs.no_release == 'false' | ||
needs: version | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: ${{ env.DOTNET_VERSION }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- 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 }}plugins/${{ env.PLUGIN_NAME }} | ||
mkdir -p plugin/${{ env.PATH_PLUGIN }}shared/${{ env.PLUGIN_NAME }} | ||
mkdir -p shared/SessionsLibrary | ||
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 }}/plugins/${{ env.PLUGIN_NAME }} | ||
cp -r ./SessionsLibrary/SessionsLibrary.dll plugin/${{ env.PATH_PLUGIN }}/shared/${{ env.PLUGIN_NAME }}/${{ env.PLUGIN_NAME }}.dll | ||
cp -r ./SessionsLibrary/SessionsLibrary.pdb plugin/${{ env.PATH_PLUGIN }}/shared/${{ env.PLUGIN_NAME }}/${{ env.PLUGIN_NAME }}.pdb | ||
cp -r ./SessionsLibrary/SessionsLibrary.deps.json plugin/${{ env.PATH_PLUGIN }}/shared/${{ env.PLUGIN_NAME }}/${{ env.PLUGIN_NAME }}.deps.json | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- name: Zip plugin | ||
run: | | ||
cd plugin/ | ||
zip -r ${{ env.PLUGIN_NAME }}-${{ github.sha }}.zip . | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Publish | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.PLUGIN_NAME }}-${{ github.sha }} | ||
path: plugin | ||
- name: Build | ||
run: dotnet build -c Release | ||
|
||
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: Publish | ||
run: dotnet publish -c Release --output ./publish | ||
|
||
- 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: Create Directories | ||
run: | | ||
mkdir -p plugin/plugins/Sessions | ||
mkdir -p plugin/shared/Sessions | ||
mv ./src/bin/Release/net8.0/* ./plugin/plugins/Sessions | ||
mv ./Sessions.API/bin/Release/* ./plugin/shared/Sessions | ||
- name: Zip | ||
run: zip -r Sessions.zip ./plugin | ||
- name: Publish | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Sessions.zip | ||
path: plugin | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
body: | | ||
This is an automated release. | ||
draft: false | ||
prerelease: false | ||
|
||
- 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}`); | ||
- name: Upload Release Asset | ||
id: upload_release_asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./ | ||
asset_name: Sessions.zip | ||
asset_content_type: application/zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
bin/ | ||
obj/ | ||
compiled/ | ||
*.sln | ||
.vs/ | ||
.vscode/ | ||
.obj/ | ||
src/bin/ | ||
src/obj/ | ||
Sessions.API/bin/ | ||
Sessions.API/obj/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.