Skip to content

Commit

Permalink
update ci configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedgefog committed Dec 29, 2022
1 parent 036720e commit 842d071
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 204 deletions.
11 changes: 5 additions & 6 deletions .amxxpack.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"compiler": {
"version": "1.9.0-git5294",
"dev": true,
"version": "1.9",
"addons": ["cstrike"]
},
"include": [
Expand All @@ -22,10 +21,10 @@
"assets": "./assets"
},
"output": {
"plugins": "./dist/reapi/addons/amxmodx/plugins",
"scripts": "./dist/reapi/addons/amxmodx/scripting",
"include": "./dist/reapi/addons/amxmodx/scripting/include",
"assets": "./dist/reapi"
"plugins": "./dist/build/addons/amxmodx/plugins",
"scripts": "./dist/build/addons/amxmodx/scripting",
"include": "./dist/build/addons/amxmodx/scripting/include",
"assets": "./dist/build"
},
"rules": {
"flatCompilation": true
Expand Down
80 changes: 26 additions & 54 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,79 +17,51 @@
uses: actions/setup-node@v1
with:
node-version: 12
- name: Setup Build Variables
id: buildvars
uses: actions/github-script@v3
- name: Install Dependencies
run: npm install
- name: Build project
run: npm run build
- name: Pack bundles
run: npm run pack
- name: Setup Release Variables
id: release_vars
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
const package = require(`${process.env.GITHUB_WORKSPACE}/package.json`);
['name', 'version', 'description', 'author']
.forEach(k => core.setOutput(k, package[k]));
['name', 'version', 'description', 'author'].forEach(k => core.setOutput(k, package[k]));
const tagVersion = package.version.replace(/\./g, '');
core.setOutput('tagversion', tagVersion);
core.setOutput('bundlename', `${package.name}-${tagVersion}`);
core.setOutput('tagname', `${package.name}-${tagVersion}`);
core.setOutput('releasename', `${package.description} Release v${package.version}`);
const bundles_metadata = require(`${process.env.GITHUB_WORKSPACE}/dist/bundles/files.json`);
core.setOutput('srcArchive', bundles_metadata.srcArchive);
core.setOutput('buildArchive', bundles_metadata.buildArchive);
core.setOutput('resourcesArchive', bundles_metadata.resourcesArchive);
core.setOutput('sdkArchive', bundles_metadata.sdkArchive);
} catch (err) {
core.setFailed(err.message);
}
- name: Install Dependencies
run: npm install
- name: Build project
run: npm run build
- name: Pack bundles
run: npm run pack
- name: Create Release
id: create_release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.buildvars.outputs.tagname }}
release_name: ${{ steps.buildvars.outputs.releasename }}
name: ${{ steps.release_vars.outputs.releasename }}
tag_name: ${{ steps.release_vars.outputs.tagname }}
draft: false
prerelease: false
- name: Upload Release Addons Src
id: upload-release-addons-src
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/bundles/zombiepanic-${{ steps.buildvars.outputs.tagversion }}-addons-src.zip
asset_name: zombiepanic-${{ steps.buildvars.outputs.tagversion }}-addons-src.zip
asset_content_type: application/zip
- name: Upload Release Build
id: upload-release-addons-reapi
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/bundles/zombiepanic-${{ steps.buildvars.outputs.tagversion }}-addons-build.zip
asset_name: zombiepanic-${{ steps.buildvars.outputs.tagversion }}-addons-build.zip
asset_content_type: application/zip
- name: Upload Release Resources
id: upload-release-resources
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/bundles/zombiepanic-${{ steps.buildvars.outputs.tagversion }}-resources.zip
asset_name: zombiepanic-${{ steps.buildvars.outputs.tagversion }}-resources.zip
asset_content_type: application/zip
- name: Upload Release SDK
id: upload-release-sdk
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/bundles/zombiepanic-${{ steps.buildvars.outputs.tagversion }}-sdk.zip
asset_name: zombiepanic-${{ steps.buildvars.outputs.tagversion }}-sdk.zip
asset_content_type: application/zip
files: |
./dist/bundles/${{ steps.release_vars.outputs.srcArchive }}
./dist/bundles/${{ steps.release_vars.outputs.buildArchive }}
./dist/bundles/${{ steps.release_vars.outputs.resourcesArchive }}
./dist/bundles/${{ steps.release_vars.outputs.sdkArchive }}
- name: Cleanup
run: |
rm -rf ./.compiler
Expand Down
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"recommendations": [
"klippy.amxxpawn-language",
"exodiusstudios.comment-anchors"
"klippy.amxxpawn-language"
]
}
7 changes: 3 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"editor.tabSize": 4,
"editor.insertSpaces": true,
"amxxpawn.compiler.executablePath": "${workspaceRoot}/compiler/amxxpc.exe",
"amxxpawn.compiler.includePaths": [
"${workspaceRoot}/compiler/include",
"${workspaceRoot}/src/include",
"${workspaceRoot}/thirdparty/reapi/addons/amxmodx/scripting/include"
"${workspaceRoot}/src/include",
"${workspaceRoot}/.compiler/include",
"${workspaceRoot}/.thirdparty/reapi/addons/amxmodx/scripting/include"
]
}
134 changes: 106 additions & 28 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,127 @@ const file = require('gulp-file');
const merge2 = require('merge2');

const package = require('./package.json');
const generateReadme = require('./helpers/bundle-readme.generator');

const README_INDENT = ' ';
const README_INSTALLATION_TEXT = 'Extract addons and resources to cstrike folder';
const WORK_DIR = process.cwd();
const DIST_DIR = path.join(WORK_DIR, './dist');
const DIST_BUILD_DIR = path.join(DIST_DIR, 'build');
const BUILD_DIR = path.join(DIST_DIR, 'bundles');
const REAPI_DIST_DIR = path.join(DIST_DIR, 'reapi');
const BUILD_METADATA_FILE = path.join(DIST_DIR, 'bundles', 'files.json');
const SDK_DIR = path.join(WORK_DIR, 'sdk');
const ASSETS_DIR = path.join(WORK_DIR, 'assets');

if (!fs.existsSync(REAPI_DIST_DIR)) {
throw new Error('Build ReAPI project before packing');
if (!fs.existsSync(DIST_BUILD_DIR)) {
throw new Error('Build project before packing');
}

function isDirEmpty(dir) {
if (!fs.existsSync(dir)) {
return true;
}

const files = fs.readdirSync(dir);

return !files.length;
}

function generateReadme(files) {
const filesArr = Object.keys(files).map(key => {
const { name, description } = files[key];
return { key, name, description };
});

const fileMaxLength = Math.max(
...filesArr.map(file => file.name.length)
);

const resolvedFiles = filesArr.map(file => {
const { name, description } = file;

if (!description) {
return;
}

const spacesNum = Math.max(fileMaxLength - name.length, 0);
const spaces = ' '.repeat(spacesNum);

return `${README_INDENT}${name}${spaces} - ${description}`
}).filter(Boolean).join('\n');

return [
'[INSTALLATION]',
`${README_INDENT}${README_INSTALLATION_TEXT}`,
'',
'[FILES]',
resolvedFiles
].join('\n');
}

const resolveArchiveName = (sufix) => `${package.name}-${package.version.replace(/\./g, '')}-${sufix}.zip`;

const FILES = {
bundleArchive: resolveArchiveName('bundle'),
srcArchive: resolveArchiveName('addons-src'),
addonsArchive: resolveArchiveName('addons-build'),
resourcesArchive: resolveArchiveName('resources'),
sdkArchive: resolveArchiveName('sdk'),
readme: 'README.TXT'
buildArchive: resolveArchiveName('addons-build'),
resourcesArchive: !isDirEmpty(ASSETS_DIR) ? resolveArchiveName('resources') : null,
sdkArchive: !isDirEmpty(SDK_DIR) ? resolveArchiveName('sdk') : null,
readme: 'README.TXT',
bundleArchive: resolveArchiveName('bundle')
};

const BUNDLE_FILES = [
{ name: FILES.addonsArchive, description: 'compiled plugins and source code' },
{ name: FILES.resourcesArchive, description: 'mod resources' },
{ name: FILES.sdkArchive, description: 'mod sdk' }
{ name: FILES.buildArchive, description: 'compiled plugins and source code' }
];

if (FILES.resourcesArchive) {
BUNDLE_FILES.push({ name: FILES.resourcesArchive, description: 'mod resources' });
}

if (FILES.sdkArchive) {
BUNDLE_FILES.push({ name: FILES.sdkArchive, description: 'mod sdk' });
}

gulp.task('pack:bundles', () => {
const dirPatterns = {
all: REAPI_DIST_DIR + '/**',
addons: REAPI_DIST_DIR + '/addons{,/**}',
plugins: REAPI_DIST_DIR + '/addons/amxmodx/plugins{,/**}',
modules: REAPI_DIST_DIR + '/addons/amxmodx/modules{,/**}',
sdk: WORK_DIR + '/sdk/**'
all: DIST_BUILD_DIR + '/**',
addons: DIST_BUILD_DIR + '/addons{,/**}',
plugins: DIST_BUILD_DIR + '/addons/amxmodx/plugins{,/**}',
modules: DIST_BUILD_DIR + '/addons/amxmodx/modules{,/**}',
sdk: SDK_DIR + '/**'
};

const zipTasks = [
(
gulp
.src([dirPatterns.addons, '!' + dirPatterns.plugins, '!' + dirPatterns.modules])
.pipe(zip(FILES.srcArchive))
),
(
gulp
.src([dirPatterns.addons])
.pipe(zip(FILES.buildArchive))
)
];

if (FILES.resourcesArchive) {
zipTasks.push(
gulp
.src([dirPatterns.all, '!' + dirPatterns.addons])
.pipe(zip(FILES.resourcesArchive))
);
}

if(FILES.sdkArchive) {
zipTasks.push(
gulp
.src([dirPatterns.sdk])
.pipe(zip(FILES.sdkArchive))
);
}

return merge2([
gulp.src([dirPatterns.addons, '!' + dirPatterns.plugins, '!' + dirPatterns.modules])
.pipe(zip(FILES.srcArchive)),
gulp.src([dirPatterns.addons])
.pipe(zip(FILES.addonsArchive)),
gulp.src([dirPatterns.all, '!' + dirPatterns.addons])
.pipe(zip(FILES.resourcesArchive)),
gulp.src([dirPatterns.sdk])
.pipe(zip(FILES.sdkArchive)),
file(FILES.readme, generateReadme(BUNDLE_FILES), {src: true})
...zipTasks,
file(FILES.readme, generateReadme(BUNDLE_FILES), { src: true })
]).pipe(gulp.dest(BUILD_DIR));
});

Expand All @@ -62,6 +136,10 @@ gulp.task('pack:full', () => {
return gulp.src(bundleFiles)
.pipe(zip(FILES.bundleArchive))
.pipe(gulp.dest(BUILD_DIR))
})
});

gulp.task('pack:metadata', cb => {
fs.writeFile(BUILD_METADATA_FILE, JSON.stringify(FILES), cb);
});

gulp.task('default', gulp.series('pack:bundles', 'pack:full'));
gulp.task('default', gulp.series('pack:bundles', 'pack:full', 'pack:metadata'));
26 changes: 0 additions & 26 deletions helpers/bundle-readme.generator.js

This file was deleted.

Loading

0 comments on commit 842d071

Please sign in to comment.