cache window bin and support dev

This commit is contained in:
ruki
2024-12-11 00:44:02 +08:00
Unverified
parent 65def61bdf
commit 014affb077
8 changed files with 8993 additions and 2301 deletions
+6 -2
View File
@@ -8,13 +8,17 @@ jobs:
checkin: checkin:
runs-on: ubuntu-latest runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-checkin
cancel-in-progress: true
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: install - name: install
uses: wyvox/action-setup-pnpm@v3 uses: wyvox/action-setup-pnpm@v3
with: with:
node-version: 20 node-version: 23
pnpm-version: 8 pnpm-version: 9
- name: build - name: build
run: pnpm build run: pnpm build
- name: test - name: test
+7 -1
View File
@@ -5,6 +5,10 @@ on:
jobs: jobs:
build: build:
concurrency:
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-${{ matrix.os }}-${{ matrix.version }}-test
cancel-in-progress: true
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
@@ -14,9 +18,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: xmake-io/github-action-setup-xmake@master - uses: xmake-io/github-action-setup-xmake@test
with: with:
xmake-version: ${{ matrix.version }} xmake-version: ${{ matrix.version }}
actions-cache-folder: '.xmake-cache'
- name: Run tests - name: Run tests
run: | run: |
xmake --version xmake --version
+11
View File
@@ -85,3 +85,14 @@ git tag v1
git push origin master git push origin master
git push --tags --force git push --tags --force
``` ```
### Development and debug
```bash
git branch test
git checkout test
pnpm build
pnpm release
git-commit -a -m "..."
git push origin test
```
+61 -1
View File
@@ -82596,6 +82596,7 @@ async function unixInstall(version) {
} }
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK); fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK);
toolDir = fullCachePath; toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
} }
catch (_c) { catch (_c) {
core.warning(`No cached files found at path "${fullCachePath}".`); core.warning(`No cached files found at path "${fullCachePath}".`);
@@ -82827,9 +82828,12 @@ const core = __nccwpck_require__(9093);
const exec_1 = __nccwpck_require__(7775); const exec_1 = __nccwpck_require__(7775);
const io = __nccwpck_require__(2826); const io = __nccwpck_require__(2826);
const toolCache = __nccwpck_require__(5561); const toolCache = __nccwpck_require__(5561);
const cache = __nccwpck_require__(6878);
const os = __nccwpck_require__(2037); const os = __nccwpck_require__(2037);
const fs = __nccwpck_require__(7147);
const path = __nccwpck_require__(1017); const path = __nccwpck_require__(1017);
const semver = __nccwpck_require__(117); const semver = __nccwpck_require__(117);
const git = __nccwpck_require__(3555);
function getInstallerUrl(version, latest) { function getInstallerUrl(version, latest) {
const ver = version.version; const ver = version.version;
switch (version.type) { switch (version.type) {
@@ -82857,12 +82861,45 @@ function getInstallerUrl(version, latest) {
} }
} }
} }
async function installFromSource(xmakeBin, sourceDir, binDir) {
await (0, exec_1.exec)(xmakeBin, ['-y'], { cwd: sourceDir });
await (0, exec_1.exec)(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
}
async function winInstall(version, latest) { async function winInstall(version, latest) {
var _a;
if (version.type === 'local' || latest.type === 'local') { if (version.type === 'local' || latest.type === 'local') {
throw new Error('Local builds for windows is not supported'); throw new Error('Local builds for windows is not supported');
} }
const actionsCacheFolder = core.getInput('actions-cache-folder');
let actionsCacheKey = core.getInput('actions-cache-key');
if (!actionsCacheKey) {
actionsCacheKey = '';
}
const ver = version.version; const ver = version.version;
let toolDir = toolCache.find('xmake', ver); const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${(_a = process.env.RUNNER_OS) !== null && _a !== void 0 ? _a : 'unknown'}`;
let toolDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
try {
try {
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
}
catch (_b) {
await cache.restoreCache([actionsCacheFolder], cacheKey);
}
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
}
catch (_c) {
core.warning(`No cached files found at path "${fullCachePath}".`);
await io.rmRF(fullCachePath);
}
}
else {
toolDir = toolCache.find('xmake', ver);
}
if (!toolDir) { if (!toolDir) {
const installer = await core.group(`download xmake ${String(version)}`, async () => { const installer = await core.group(`download xmake ${String(version)}`, async () => {
const url = getInstallerUrl(version, latest); const url = getInstallerUrl(version, latest);
@@ -82887,6 +82924,29 @@ async function winInstall(version, latest) {
await io.rmRF(installer); await io.rmRF(installer);
return cacheDir; return cacheDir;
}); });
await (0, exec_1.exec)(`"${toolDir}/xmake.exe" --version`);
if (version.type === 'heads') {
const sourceDir = await core.group(`download xmake source ${String(version)}`, () => git.create(version.repo, version.sha));
toolDir = await core.group(`install xmake source ${String(version)}`, async () => {
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
await installFromSource(`${toolDir}/xmake.exe`, `${sourceDir}/core`, binDir);
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
await io.rmRF(binDir);
await git.cleanup(version.sha);
return cacheDir;
});
}
if (toolDir) {
let cacheDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
cacheDir = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
await io.cp(toolDir, cacheDir, {
recursive: true,
});
await cache.saveCache([actionsCacheFolder], cacheKey);
toolDir = cacheDir;
}
}
} }
core.addPath(toolDir); core.addPath(toolDir);
} }
+6092
View File
File diff suppressed because it is too large Load Diff
+2748 -2296
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -46,6 +46,7 @@ export async function unixInstall(version: Version): Promise<void> {
} }
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK); fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK);
toolDir = fullCachePath; toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
} catch { } catch {
core.warning(`No cached files found at path "${fullCachePath}".`); core.warning(`No cached files found at path "${fullCachePath}".`);
await io.rmRF(fullCachePath); await io.rmRF(fullCachePath);
+67 -1
View File
@@ -2,9 +2,12 @@ import * as core from '@actions/core';
import { exec } from '@actions/exec'; import { exec } from '@actions/exec';
import * as io from '@actions/io'; import * as io from '@actions/io';
import * as toolCache from '@actions/tool-cache'; import * as toolCache from '@actions/tool-cache';
import * as cache from '@actions/cache';
import * as os from 'os'; import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as git from './git';
import { Version, GitVersion } from './interfaces'; import { Version, GitVersion } from './interfaces';
function getInstallerUrl(version: GitVersion, latest: GitVersion): string { function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
@@ -35,12 +38,48 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
} }
} }
async function installFromSource(xmakeBin: string, sourceDir: string, binDir: string): Promise<void> {
await exec(xmakeBin, ['-y'], { cwd: sourceDir });
await exec(xmakeBin, ['install', '-o', binDir, 'cli'], { cwd: sourceDir });
}
export async function winInstall(version: Version, latest: Version): Promise<void> { export async function winInstall(version: Version, latest: Version): Promise<void> {
if (version.type === 'local' || latest.type === 'local') { if (version.type === 'local' || latest.type === 'local') {
throw new Error('Local builds for windows is not supported'); throw new Error('Local builds for windows is not supported');
} }
const actionsCacheFolder = core.getInput('actions-cache-folder');
let actionsCacheKey = core.getInput('actions-cache-key');
if (!actionsCacheKey) {
actionsCacheKey = '';
}
const ver = version.version; const ver = version.version;
let toolDir = toolCache.find('xmake', ver); const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${
process.env.RUNNER_OS ?? 'unknown'
}`;
let toolDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
try {
try {
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
} catch {
await cache.restoreCache([actionsCacheFolder], cacheKey);
}
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`);
} catch {
core.warning(`No cached files found at path "${fullCachePath}".`);
await io.rmRF(fullCachePath);
}
} else {
toolDir = toolCache.find('xmake', ver);
}
if (!toolDir) { if (!toolDir) {
const installer = await core.group(`download xmake ${String(version)}`, async () => { const installer = await core.group(`download xmake ${String(version)}`, async () => {
const url = getInstallerUrl(version, latest); const url = getInstallerUrl(version, latest);
@@ -65,6 +104,33 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
await io.rmRF(installer); await io.rmRF(installer);
return cacheDir; return cacheDir;
}); });
await exec(`"${toolDir}/xmake.exe" --version`);
if (version.type === 'heads') {
const sourceDir = await core.group(`download xmake source ${String(version)}`, () =>
git.create(version.repo, version.sha),
);
toolDir = await core.group(`install xmake source ${String(version)}`, async () => {
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
await installFromSource(`${toolDir}/xmake.exe`, `${sourceDir}/core`, binDir);
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
await io.rmRF(binDir);
await git.cleanup(version.sha);
return cacheDir;
});
}
if (toolDir) {
let cacheDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
cacheDir = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
await io.cp(toolDir, cacheDir, {
recursive: true,
});
await cache.saveCache([actionsCacheFolder], cacheKey);
toolDir = cacheDir;
}
}
} }
core.addPath(toolDir); core.addPath(toolDir);
} }