Compare commits
59 Commits
+2
-6
@@ -20,9 +20,9 @@ rules:
|
||||
- 1
|
||||
- allowWithDecorator: true
|
||||
allowStaticOnly: true
|
||||
'@typescript-eslint/no-parameter-properties':
|
||||
'@typescript-eslint/parameter-properties':
|
||||
- 1
|
||||
- allows: [protected readonly, private readonly, public readonly, readonly]
|
||||
- allow: [protected readonly, private readonly, public readonly, readonly]
|
||||
'@typescript-eslint/no-throw-literal': [2]
|
||||
'no-unused-vars': [0]
|
||||
'@typescript-eslint/no-unused-vars':
|
||||
@@ -33,9 +33,5 @@ rules:
|
||||
'@typescript-eslint/prefer-function-type': [1]
|
||||
'@typescript-eslint/prefer-nullish-coalescing': [1]
|
||||
'@typescript-eslint/prefer-optional-chain': [1]
|
||||
'@typescript-eslint/ban-types':
|
||||
- 1
|
||||
- types:
|
||||
object: false
|
||||
no-void: [1, { allowAsStatement: true }]
|
||||
eqeqeq: [1, smart]
|
||||
|
||||
@@ -8,30 +8,28 @@ jobs:
|
||||
checkin:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [16.x]
|
||||
concurrency:
|
||||
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-checkin
|
||||
cancel-in-progress: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'yarn'
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: yarn install --frozen-lockfile
|
||||
uses: wyvox/action-setup-pnpm@v3
|
||||
with:
|
||||
node-version: 23
|
||||
pnpm-version: 9
|
||||
- name: build
|
||||
run: yarn build
|
||||
run: pnpm build
|
||||
- name: test
|
||||
run: yarn test
|
||||
run: pnpm test
|
||||
- name: release
|
||||
run: yarn release
|
||||
run: pnpm release
|
||||
- name: 'check for uncommitted changes'
|
||||
# Ensure no changes
|
||||
run: |
|
||||
git add .
|
||||
if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then
|
||||
echo "::error::Found changed files after build. Please run 'yarn release' and check in all changes."
|
||||
echo "::error::Found changed files after build. Please run 'pnpm release' and check in all changes."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -5,6 +5,10 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
concurrency:
|
||||
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-${{ matrix.os }}-${{ matrix.version }}-test
|
||||
cancel-in-progress: true
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
@@ -17,9 +21,17 @@ jobs:
|
||||
- uses: xmake-io/github-action-setup-xmake@master
|
||||
with:
|
||||
xmake-version: ${{ matrix.version }}
|
||||
actions-cache-folder: '.xmake-cache'
|
||||
actions-cache-key: ${{ matrix.version }}
|
||||
build-cache: true
|
||||
build-cache-key: ${{ matrix.version }}
|
||||
package-cache: true
|
||||
package-cache-key: ${{ matrix.version }}
|
||||
project-path: 'tests/sample'
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
xmake --version
|
||||
xmake create -P test
|
||||
xmake build -P test
|
||||
xmake run -P test
|
||||
cd tests/sample
|
||||
xmake -y -vD
|
||||
xmake run
|
||||
|
||||
+23
-1
@@ -1 +1,23 @@
|
||||
node_modules
|
||||
# dependencies
|
||||
/node_modules/
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
*.log
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"npm.packageManager": "yarn",
|
||||
"npm.packageManager": "pnpm",
|
||||
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
|
||||
"eslint.enable": true,
|
||||
"files.autoSave": "off",
|
||||
@@ -7,7 +7,7 @@
|
||||
"editor.tabSize": 4,
|
||||
"editor.formatOnSave": false,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
||||
|
||||
@@ -11,7 +11,7 @@ See [action.yml](./action.yml).
|
||||
|
||||
## Example
|
||||
|
||||
Use latest version:
|
||||
### Use latest version
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
@@ -19,7 +19,7 @@ with:
|
||||
xmake-version: latest
|
||||
```
|
||||
|
||||
Use specified version:
|
||||
### Use specified version
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
@@ -27,7 +27,7 @@ with:
|
||||
xmake-version: '2.5.3'
|
||||
```
|
||||
|
||||
Use specified branch:
|
||||
### Use specified branch
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
@@ -35,7 +35,7 @@ with:
|
||||
xmake-version: branch@master
|
||||
```
|
||||
|
||||
Use semver:
|
||||
### Use semver
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
@@ -43,20 +43,89 @@ with:
|
||||
xmake-version: '>=2.2.6 <=2.5.3'
|
||||
```
|
||||
|
||||
### Cache xmake
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: '2.9.7'
|
||||
actions-cache-folder: '.xmake-cache'
|
||||
```
|
||||
|
||||
### Cache xmake with cachekey
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: '2.9.7'
|
||||
actions-cache-folder: '.xmake-cache'
|
||||
actions-cache-key: 'archlinux-ci'
|
||||
```
|
||||
|
||||
### Cache packages
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: '2.9.7'
|
||||
package-cache: true
|
||||
package-cache-key: 'archlinux-ci'
|
||||
project-path: 'myproject' # we need to compute packages hashkey for project
|
||||
```
|
||||
|
||||
### Cache build
|
||||
|
||||
By default, xmake disables build cache when building on ci, so we need to enable it first.
|
||||
|
||||
```bash
|
||||
$ xmake f --policies=build.ccache:y
|
||||
```
|
||||
|
||||
And xmake v2.9.8 will enable it by default if action/build-cache is enabled.
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: '2.9.7'
|
||||
build-cache: true
|
||||
build-cache-key: 'archlinux-ci'
|
||||
```
|
||||
|
||||
Cache build with the specific project path.
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: '2.9.7'
|
||||
build-cache: true
|
||||
project-path: 'myproject' # we can get the build cache path from project.
|
||||
```
|
||||
|
||||
Cache build with the specific build path.
|
||||
|
||||
```yml
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: '2.9.7'
|
||||
build-cache: true
|
||||
build-cache-path: 'build/.build_cache'
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
### Prepare development environment
|
||||
|
||||
```bash
|
||||
yarn install
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### Draft a new release
|
||||
|
||||
```bash
|
||||
yarn release
|
||||
pnpm release
|
||||
git add .
|
||||
yarn version
|
||||
git commit -m "build: release"
|
||||
pnpm version [new-version]
|
||||
|
||||
# for a minor version or patch of v1
|
||||
git tag --delete v1
|
||||
@@ -65,3 +134,14 @@ git tag v1
|
||||
git push origin master
|
||||
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
|
||||
```
|
||||
|
||||
+24
-1
@@ -13,6 +13,29 @@ inputs:
|
||||
actions-cache-folder:
|
||||
description: 'Directory to cache xmake in. This folder will go under $GITHUB_HOME (I.e. build dir) and be cached using @actions/cache.'
|
||||
default: ''
|
||||
actions-cache-key:
|
||||
description: The actions cache key.
|
||||
default: ''
|
||||
package-cache:
|
||||
description: Enable package cache.
|
||||
default: false
|
||||
package-cache-key:
|
||||
description: The packages cache key.
|
||||
default: ''
|
||||
project-path:
|
||||
description: The project root path.
|
||||
default: ''
|
||||
build-cache:
|
||||
description: Enable build cache.
|
||||
default: false
|
||||
build-cache-path:
|
||||
description: The build cache path.
|
||||
default: ''
|
||||
build-cache-key:
|
||||
description: The build cache key.
|
||||
default: ''
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
post: 'dist/index.js'
|
||||
|
||||
Vendored
+34273
-17862
File diff suppressed because one or more lines are too long
Generated
+6092
File diff suppressed because it is too large
Load Diff
+22
-22
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "github-action-setup-xmake",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.3",
|
||||
"description": "Set up your GitHub Actions workflow with a specific version of xmake",
|
||||
"main": "dist/index.js",
|
||||
"author": "OpportunityLiu",
|
||||
@@ -10,37 +10,37 @@
|
||||
"scripts": {
|
||||
"watch": "tsc --watch",
|
||||
"build": "ncc build src/index.ts",
|
||||
"rebuild": "yarn clean && yarn build",
|
||||
"rebuild": "pnpm clean && pnpm build",
|
||||
"clean": "rimraf dist",
|
||||
"lint": "eslint --fix src/**/*.ts",
|
||||
"format": "prettier --write .",
|
||||
"test": "jest",
|
||||
"release": "yarn clean && yarn format && yarn lint && yarn build"
|
||||
"release": "pnpm clean && pnpm format && pnpm lint && pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.0.6",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/cache": "^3.2.4",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/io": "^1.1.2",
|
||||
"@actions/io": "^1.1.3",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"semver": "^7.3.5"
|
||||
"semver": "^7.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/node": "^16.3.2",
|
||||
"@types/semver": "^7.3.7",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.3",
|
||||
"@typescript-eslint/parser": "^4.28.3",
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"eslint": "^7.30.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"jest": "^27.0.6",
|
||||
"prettier": "^2.3.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^27.0.3",
|
||||
"type-fest": "^1.2.2",
|
||||
"typescript": "^4.3.5"
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/node": "^20.12.4",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
||||
"@typescript-eslint/parser": "^7.5.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.2.5",
|
||||
"rimraf": "^5.0.5",
|
||||
"ts-jest": "^29.1.2",
|
||||
"type-fest": "^4.15.0",
|
||||
"typescript": "^5.4.4"
|
||||
},
|
||||
"contributors": [
|
||||
"Yu Zhu"
|
||||
|
||||
Generated
+4448
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,159 @@
|
||||
import * as core from '@actions/core';
|
||||
import { exec, ExecOptions } from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as fsutils from './fsutils';
|
||||
|
||||
function getBuildTime(hours?: string): string {
|
||||
let key = 'BuildTime';
|
||||
if (hours && hours !== '') {
|
||||
key = key + hours;
|
||||
}
|
||||
let buildTime = core.getState(key);
|
||||
if (!buildTime || buildTime === '') {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
if (!hours || hours === '') {
|
||||
hours = String(now.getHours()).padStart(2, '0');
|
||||
}
|
||||
buildTime = `${year}${month}${day}_${hours}`;
|
||||
core.saveState(key, buildTime);
|
||||
}
|
||||
return buildTime;
|
||||
}
|
||||
|
||||
function getProjectRootPath(): string {
|
||||
let projectRootPath = core.getInput('project-path');
|
||||
if (!projectRootPath) {
|
||||
projectRootPath = process.cwd();
|
||||
}
|
||||
projectRootPath = projectRootPath.trim();
|
||||
if (projectRootPath && projectRootPath !== '' && !path.isAbsolute(projectRootPath)) {
|
||||
projectRootPath = path.join(process.cwd(), projectRootPath);
|
||||
}
|
||||
return projectRootPath;
|
||||
}
|
||||
|
||||
function getBuildCacheKey(buildCacheTime?: string): string {
|
||||
let buildCacheKey = core.getInput('build-cache-key');
|
||||
if (!buildCacheKey) {
|
||||
buildCacheKey = '';
|
||||
}
|
||||
if (!buildCacheTime || buildCacheTime === '') {
|
||||
buildCacheTime = getBuildTime();
|
||||
}
|
||||
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
|
||||
}
|
||||
|
||||
async function getBuildCachePath(): Promise<string> {
|
||||
let buildCachePath = core.getInput('build-cache-path');
|
||||
if (!buildCachePath) {
|
||||
buildCachePath = '';
|
||||
const projectRootPath = getProjectRootPath();
|
||||
if (projectRootPath && projectRootPath !== '' && fsutils.isDir(projectRootPath)) {
|
||||
const options: ExecOptions = {};
|
||||
options.cwd = projectRootPath;
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
buildCachePath += data.toString();
|
||||
},
|
||||
};
|
||||
await exec(
|
||||
'xmake',
|
||||
[
|
||||
'l',
|
||||
'-c',
|
||||
'import("core.project.config"); import("private.cache.build_cache"); config.load(); print(build_cache.rootdir())',
|
||||
],
|
||||
options,
|
||||
);
|
||||
buildCachePath = buildCachePath.trim();
|
||||
if (buildCachePath !== '' && !path.isAbsolute(buildCachePath)) {
|
||||
buildCachePath = path.join(projectRootPath, buildCachePath);
|
||||
}
|
||||
} else {
|
||||
buildCachePath = 'build/.build_cache';
|
||||
}
|
||||
}
|
||||
return buildCachePath;
|
||||
}
|
||||
|
||||
function getBuildCacheFolder(): string {
|
||||
return '.xmake-build-cache';
|
||||
}
|
||||
|
||||
export async function loadBuildCache(): Promise<void> {
|
||||
const buildCache = core.getBooleanInput('build-cache');
|
||||
if (!buildCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
// export $XMAKE_ACTION_BUILD_CACHE, xmake will check it and enable build cache by default on ci.
|
||||
core.exportVariable('XMAKE_ACTION_BUILD_CACHE', 'true');
|
||||
|
||||
const buildCacheFolder = getBuildCacheFolder();
|
||||
const buildCachePath = await getBuildCachePath();
|
||||
|
||||
if (buildCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||
const filepath = path.join(fullCachePath, 'build_cache_saved.txt');
|
||||
// Since action/cache cannot overwrite updates, we try to restore the cache from the last 24 hours.
|
||||
const now = new Date();
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const hours = now.getHours() - i;
|
||||
if (hours < 0) {
|
||||
break;
|
||||
}
|
||||
const buildCacheKey = getBuildCacheKey(getBuildTime(String(hours).padStart(2, '0')));
|
||||
if (!fsutils.isFile(filepath)) {
|
||||
core.info(`Restore build cache path: ${fullCachePath} to ${buildCachePath}, key: ${buildCacheKey}`);
|
||||
await cache.restoreCache([buildCacheFolder], buildCacheKey);
|
||||
}
|
||||
if (fsutils.isFile(filepath)) {
|
||||
if (fsutils.isDir(buildCachePath)) {
|
||||
await io.rmRF(buildCachePath);
|
||||
}
|
||||
await io.cp(fullCachePath, buildCachePath, {
|
||||
recursive: true,
|
||||
});
|
||||
/* Even if the historical cache is hit, we need to update to the latest cache
|
||||
* Therefore, only when the latest cache is hit, it is a real hit, and we no longer need to update the cache.
|
||||
*/
|
||||
if (i === 0) {
|
||||
core.saveState('hitBuildCache', 'true');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fsutils.isFile(filepath)) {
|
||||
core.warning(`No cached files found at path "${fullCachePath}".`);
|
||||
await io.rmRF(fullCachePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveBuildCache(): Promise<void> {
|
||||
const buildCache = core.getBooleanInput('build-cache');
|
||||
if (!buildCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
const buildCacheFolder = getBuildCacheFolder();
|
||||
const buildCacheKey = getBuildCacheKey();
|
||||
const buildCachePath = await getBuildCachePath();
|
||||
|
||||
const hitBuildCache = !!core.getState('hitBuildCache');
|
||||
if (!hitBuildCache && buildCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(buildCachePath)) {
|
||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, buildCacheFolder);
|
||||
core.info(`Save build cache path: ${buildCachePath} to ${fullCachePath}, key: ${buildCacheKey}`);
|
||||
await io.cp(buildCachePath, fullCachePath, {
|
||||
recursive: true,
|
||||
});
|
||||
await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'build_cache_saved.txt')]);
|
||||
await cache.saveCache([buildCacheFolder], buildCacheKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import * as fs from 'fs';
|
||||
|
||||
export function isFile(filepath: string): boolean {
|
||||
try {
|
||||
fs.accessSync(filepath, fs.constants.F_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isDir(filepath: string): boolean {
|
||||
try {
|
||||
const stats = fs.statSync(filepath);
|
||||
if (stats.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ export async function lsRemote(repo: Repo): Promise<RefDic> {
|
||||
const data: RefDic = { heads: {}, tags: {}, pull: {} };
|
||||
out.split('\n').forEach((line) => {
|
||||
const [ref, tag] = line.trim().split('\t');
|
||||
if (ref && tag && tag.startsWith('refs/')) {
|
||||
if (ref && tag?.startsWith('refs/')) {
|
||||
const tagPath = tag.split('/').splice(1);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let ldata = data as any; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
||||
|
||||
+22
-14
@@ -1,24 +1,32 @@
|
||||
import * as core from '@actions/core';
|
||||
import { exec } from '@actions/exec';
|
||||
import * as os from 'os';
|
||||
import { selectVersion } from './versions';
|
||||
import { winInstall } from './win-install';
|
||||
import { unixInstall } from './unix-install';
|
||||
import * as stateHelper from './state-helper';
|
||||
import { installXmake } from './install';
|
||||
import { loadBuildCache, saveBuildCache } from './build-cache';
|
||||
import { loadPackageCache, savePackageCache } from './package-cache';
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const version = await selectVersion();
|
||||
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
|
||||
const latest = await selectVersion('latest');
|
||||
await winInstall(version, latest);
|
||||
} else {
|
||||
await unixInstall(version);
|
||||
}
|
||||
await exec('xmake --version');
|
||||
await installXmake();
|
||||
await loadBuildCache();
|
||||
await loadPackageCache();
|
||||
} catch (error) {
|
||||
const ex = error as Error;
|
||||
core.setFailed(ex.message);
|
||||
}
|
||||
}
|
||||
|
||||
run().catch((e) => core.error(e));
|
||||
async function saveCache(): Promise<void> {
|
||||
try {
|
||||
await saveBuildCache();
|
||||
await savePackageCache();
|
||||
} catch (error) {
|
||||
const ex = error as Error;
|
||||
core.setFailed(ex.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!stateHelper.IsPost) {
|
||||
run().catch((e: Error) => core.error(e));
|
||||
} else {
|
||||
saveCache().catch((e: Error) => core.error(e));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { exec } from '@actions/exec';
|
||||
import * as os from 'os';
|
||||
import { selectVersion } from './versions';
|
||||
import { winInstall } from './win-install';
|
||||
import { unixInstall } from './unix-install';
|
||||
|
||||
export async function installXmake(): Promise<void> {
|
||||
const version = await selectVersion();
|
||||
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
|
||||
const latest = await selectVersion('latest');
|
||||
await winInstall(version, latest);
|
||||
} else {
|
||||
await unixInstall(version);
|
||||
}
|
||||
await exec('xmake --root --version');
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import * as core from '@actions/core';
|
||||
import { exec, ExecOptions } from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as fsutils from './fsutils';
|
||||
|
||||
function getProjectRootPath(): string {
|
||||
let projectRootPath = core.getInput('project-path');
|
||||
if (!projectRootPath) {
|
||||
projectRootPath = process.cwd();
|
||||
}
|
||||
projectRootPath = projectRootPath.trim();
|
||||
if (projectRootPath && projectRootPath !== '' && !path.isAbsolute(projectRootPath)) {
|
||||
projectRootPath = path.join(process.cwd(), projectRootPath);
|
||||
}
|
||||
return projectRootPath;
|
||||
}
|
||||
|
||||
async function getPackageCacheKey(): Promise<string> {
|
||||
let packageCacheKey = core.getInput('package-cache-key');
|
||||
if (!packageCacheKey) {
|
||||
packageCacheKey = '';
|
||||
}
|
||||
let packageCacheHash = '';
|
||||
const projectRootPath = getProjectRootPath();
|
||||
if (projectRootPath && projectRootPath !== '' && fsutils.isDir(projectRootPath)) {
|
||||
const options: ExecOptions = {};
|
||||
options.cwd = projectRootPath;
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
packageCacheHash += data.toString();
|
||||
},
|
||||
};
|
||||
await exec('xmake', ['repo', '--update']);
|
||||
await exec('xmake', ['l', 'utils.ci.packageskey'], options);
|
||||
packageCacheHash = packageCacheHash.trim();
|
||||
}
|
||||
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
|
||||
}
|
||||
|
||||
async function getPackageCachePath(): Promise<string> {
|
||||
let packageCachePath = '';
|
||||
const options: ExecOptions = {};
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
packageCachePath += data.toString();
|
||||
},
|
||||
};
|
||||
await exec('xmake', ['l', '-c', 'import("core.package.package"); print(package.installdir())'], options);
|
||||
packageCachePath = packageCachePath.trim();
|
||||
return packageCachePath;
|
||||
}
|
||||
|
||||
function getPackageCacheFolder(): string {
|
||||
return '.xmake-package-cache';
|
||||
}
|
||||
|
||||
export async function loadPackageCache(): Promise<void> {
|
||||
const packageCache = core.getBooleanInput('package-cache');
|
||||
if (!packageCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
const packageCacheFolder = getPackageCacheFolder();
|
||||
const packageCacheKey = await getPackageCacheKey();
|
||||
const packageCachePath = await getPackageCachePath();
|
||||
if (!packageCachePath || packageCachePath === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packageCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, packageCacheFolder);
|
||||
const filepath = path.join(fullCachePath, 'package_cache_saved.txt');
|
||||
if (!fsutils.isFile(filepath)) {
|
||||
core.info(`Restore package cache path: ${fullCachePath} to ${packageCachePath}, key: ${packageCacheKey}`);
|
||||
await cache.restoreCache([packageCacheFolder], packageCacheKey);
|
||||
}
|
||||
if (fsutils.isFile(filepath)) {
|
||||
if (fsutils.isDir(packageCachePath)) {
|
||||
await io.rmRF(packageCachePath);
|
||||
}
|
||||
await io.cp(fullCachePath, packageCachePath, {
|
||||
recursive: true,
|
||||
});
|
||||
core.saveState('hitPackageCache', 'true');
|
||||
} else {
|
||||
core.warning(`No cached files found at path "${fullCachePath}".`);
|
||||
await io.rmRF(fullCachePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function savePackageCache(): Promise<void> {
|
||||
const packageCache = core.getBooleanInput('package-cache');
|
||||
if (!packageCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
const packageCacheFolder = getPackageCacheFolder();
|
||||
const packageCacheKey = await getPackageCacheKey();
|
||||
const packageCachePath = await getPackageCachePath();
|
||||
if (!packageCachePath || packageCachePath === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
const hitPackageCache = !!core.getState('hitPackageCache');
|
||||
if (!hitPackageCache && packageCacheFolder && process.env.GITHUB_WORKSPACE && fsutils.isDir(packageCachePath)) {
|
||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, packageCacheFolder);
|
||||
core.info(`Save package cache path: ${packageCachePath} to ${fullCachePath}, key: ${packageCacheKey}`);
|
||||
await io.cp(packageCachePath, fullCachePath, {
|
||||
recursive: true,
|
||||
});
|
||||
await cache.saveCache([packageCacheFolder], packageCacheKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import * as core from '@actions/core';
|
||||
|
||||
/**
|
||||
* Indicates whether the POST action is running
|
||||
*/
|
||||
export const IsPost = !!core.getState('isPost');
|
||||
|
||||
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
||||
// This is necessary since we don't have a separate entry point.
|
||||
if (!IsPost) {
|
||||
core.saveState('isPost', 'true');
|
||||
}
|
||||
+16
-2
@@ -11,17 +11,30 @@ import * as git from './git';
|
||||
import { Version } from './interfaces';
|
||||
|
||||
async function install(sourceDir: string, binDir: string): Promise<void> {
|
||||
await exec('make', ['build'], { cwd: sourceDir });
|
||||
if (fs.existsSync(path.join(sourceDir, 'configure'))) {
|
||||
await exec('sh', ['./configure'], { cwd: sourceDir });
|
||||
await exec('make', ['-j6'], { cwd: sourceDir });
|
||||
await exec('make', ['install', `PREFIX=${binDir}`], { cwd: sourceDir });
|
||||
} else {
|
||||
await exec('make', ['-j6'], { cwd: sourceDir });
|
||||
await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
||||
}
|
||||
}
|
||||
|
||||
export async function unixInstall(version: Version): Promise<void> {
|
||||
let toolDir = '';
|
||||
const actionsCacheFolder = core.getInput('actions-cache-folder');
|
||||
let actionsCacheKey = core.getInput('actions-cache-key');
|
||||
if (!actionsCacheKey) {
|
||||
actionsCacheKey = '';
|
||||
}
|
||||
|
||||
if (version.type !== 'local') {
|
||||
const ver = version.version;
|
||||
const cacheKey = `xmake-cache-${ver}-${os.arch()}-${os.platform()}-${process.env.RUNNER_OS ?? 'unknown'}`;
|
||||
const sha = version.sha;
|
||||
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${
|
||||
process.env.RUNNER_OS ?? 'unknown'
|
||||
}`;
|
||||
|
||||
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
|
||||
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
|
||||
@@ -33,6 +46,7 @@ export async function unixInstall(version: Version): Promise<void> {
|
||||
}
|
||||
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), 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);
|
||||
|
||||
+71
-2
@@ -2,17 +2,23 @@ import * as core from '@actions/core';
|
||||
import { exec } from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as git from './git';
|
||||
import { Version, GitVersion } from './interfaces';
|
||||
|
||||
function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
||||
const ver = version.version;
|
||||
let ver = version.version;
|
||||
switch (version.type) {
|
||||
case 'heads': {
|
||||
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
||||
const latestver = latest.version;
|
||||
if (ver !== 'dev' && ver !== 'master') {
|
||||
ver = latestver;
|
||||
}
|
||||
return `https://github.com/xmake-io/xmake/releases/download/${latestver}/xmake-${ver}.${arch}.exe`;
|
||||
}
|
||||
case 'pull': {
|
||||
@@ -35,12 +41,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> {
|
||||
if (version.type === 'local' || latest.type === 'local') {
|
||||
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;
|
||||
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) {
|
||||
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
||||
const url = getInstallerUrl(version, latest);
|
||||
@@ -65,6 +107,33 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
|
||||
await io.rmRF(installer);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Xmake cache
|
||||
.xmake/
|
||||
build/
|
||||
|
||||
# MacOS Cache
|
||||
.DS_Store
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "hello world!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
add_requires("libpng", "libogg", {system = false})
|
||||
|
||||
target("sample")
|
||||
set_kind("binary")
|
||||
add_files("src/*.cpp")
|
||||
add_packages("libpng", "libogg")
|
||||
|
||||
Reference in New Issue
Block a user