Skip to content

Commit

Permalink
ci: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Nov 8, 2024
1 parent 80526d3 commit 1618793
Show file tree
Hide file tree
Showing 6 changed files with 662 additions and 39 deletions.
14 changes: 14 additions & 0 deletions .github/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { execSync } = require('child_process');
const arch = process.env.MATRIX_ARCH;
const os = process.env.MATRIX_OS;
const rustTarget = process.env.MATRIX_RUST_TARGET;

if (arch === 'arm64' && os === 'ubuntu-latest') {
console.log('Using cross to build...');
execSync('cross build -p jsonui_lsp --verbose --release --target=' + rustTarget, { stdio: 'inherit' });
} else {
console.log('Using cargo to build...');
execSync('rustup set auto-self-update disable', { stdio: 'inherit' });
execSync('rustup target add ' + rustTarget, { stdio: 'inherit' });
execSync('cargo build -p jsonui_lsp --verbose --release --target=' + rustTarget, { stdio: 'inherit' });
}
20 changes: 20 additions & 0 deletions .github/scripts/moveRelease.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs');
const path = require('path');

const targetDir = process.env.TARGET;
const sourcePaths = [
'target/' + targetDir + '/release/jsonui_lsp',
'target/' + targetDir + '/release/jsonui_lsp.exe'
];
const destDir = 'dist';

sourcePaths.forEach(sourcePath => {
const destPath = path.join(destDir, path.basename(sourcePath));

if (fs.existsSync(sourcePath)) {
fs.renameSync(sourcePath, destPath);
console.log('File', path.basename(sourcePath), 'moved successfully to', destPath);
} else {
console.log('File', path.basename(sourcePath), 'not found at', sourcePath);
}
});
10 changes: 10 additions & 0 deletions .github/scripts/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const commitMessage = process.env.GITHUB_EVENT_HEAD_COMMIT_MESSAGE;
const target = process.env.TARGET;

const execSync = require('child_process').execSync;

if (commitMessage.includes('-pre')) {
execSync('npx vsce package --pre-release --target ' + target, { stdio: 'inherit' });
} else {
execSync('npx vsce package --target ' + target, { stdio: 'inherit' });
}
15 changes: 6 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ jobs:
if: matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest'
run: cargo install cross
- name: Build with Cargo or Cross
run: |
node -e "const { execSync } = require('child_process'); const arch = process.env.MATRIX_ARCH; const os = process.env.MATRIX_OS; const rustTarget = process.env.MATRIX_RUST_TARGET; if (arch === 'arm64' && os === 'ubuntu-latest') { console.log('Using cross to build...'); execSync('cross build --verbose --release --target=' + rustTarget, { stdio: 'inherit' }); } else { console.log('Using cargo to build...'); execSync('rustup set auto-self-update disable', { stdio: 'inherit' }); execSync('rustup target add ' + rustTarget, { stdio: 'inherit' }); execSync('cargo build --verbose --release --target=' + rustTarget, { stdio: 'inherit' }); }"
run: node ./github/scripts/build.js
env:
MATRIX_ARCH: ${{ matrix.arch }}
MATRIX_OS: ${{ matrix.os }}
Expand All @@ -65,17 +64,15 @@ jobs:
- name: build client and move execute file
run: |
npx webpack --mode production --config webpack.config.js
node -e "const fs = require('fs'); const path = require('path'); const targetDir = process.env.TARGET; const sourcePaths = ['target/' + targetDir + '/release/jsonui-lsp', 'target/' + targetDir + '/release/jsonui-lsp.exe']; const destDir = 'dist'; sourcePaths.forEach(sourcePath => { const destPath = path.join(destDir, path.basename(sourcePath)); if (fs.existsSync(sourcePath)) { fs.renameSync(sourcePath, destPath); console.log('File', path.basename(sourcePath), 'moved successfully to', destPath); } else { console.log('File', path.basename(sourcePath), 'not found at', sourcePath); } });"
node .github/scripts/moveRelease.js
env:
TARGET: ${{ matrix.rust_target }}
- shell: pwsh
run: echo "target=${{ matrix.platform }}-${{ matrix.arch }}" >> $env:GITHUB_ENV
- run: |
if [[ "${{ github.event.head_commit.message }}" == *"-pre"* ]]; then
npx vsce package --pre-release --target ${{ env.target }}
else
npx vsce package --target ${{ env.target }}
fi
- run: node .github/scripts/package.js
env:
GITHUB_EVENT_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
TARGET: ${{ env.target }}
- uses: actions/upload-artifact@v4
with:
name: ${{ env.target }}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"license": "MIT",
"version": "0.0.8",
"icon": "icon.png",
"categories": ["Snippets"],
"categories": [
"Snippets"
],
"keywords": [
"minecraft",
"bedrock",
Expand Down Expand Up @@ -80,6 +82,7 @@
"eslint": "^7.6.0",
"glob": "^7.1.7",
"mocha": "^8.0.1",
"vsce": "^2.15.0",
"rimraf": "^6.0.1",
"ts-loader": "^9.5.1",
"typescript": "5.4.5",
Expand Down
Loading

0 comments on commit 1618793

Please sign in to comment.