Compare commits

..

67 Commits

22 changed files with 53765 additions and 55732 deletions
+5 -3
View File
@@ -13,12 +13,12 @@ jobs:
cancel-in-progress: true cancel-in-progress: true
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v6
- name: install - name: install
uses: wyvox/action-setup-pnpm@v3 uses: wyvox/action-setup-pnpm@v3
with: with:
node-version: 23 node-version: 24
pnpm-version: 9 pnpm-version: 10
- name: build - name: build
run: pnpm build run: pnpm build
- name: test - name: test
@@ -28,6 +28,8 @@ jobs:
- name: 'check for uncommitted changes' - name: 'check for uncommitted changes'
# Ensure no changes # Ensure no changes
run: | run: |
pnpm --version
node --version
git add . git add .
if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then
echo "::error::Found changed files after build. Please run 'pnpm release' and check in all changes." echo "::error::Found changed files after build. Please run 'pnpm release' and check in all changes."
+33 -7
View File
@@ -11,21 +11,47 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, windows-11-arm, macOS-latest]
version: [latest, branch@master, branch@dev] version: [latest, branch@master, branch@dev]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v6
- uses: xmake-io/github-action-setup-xmake@test - uses: xmake-io/github-action-setup-xmake@master
with: with:
xmake-version: ${{ matrix.version }} xmake-version: ${{ matrix.version }}
actions-cache-folder: '.xmake-cache' actions-cache-folder: '.xmake-cache'
actions-cache-key: ${{ matrix.version }}-relative
build-cache: true
build-cache-key: ${{ matrix.version }}-relative
package-cache: true
package-cache-key: ${{ matrix.version }}-relative
project-path: 'tests/sample'
- name: Run tests - name: Run tests with relative cache path
run: | run: |
xmake --version xmake --version
xmake create -P test cd tests/sample
xmake build -P test xmake -y -vD
xmake run -P test xmake run
xmake clean
- uses: xmake-io/github-action-setup-xmake@master
with:
xmake-version: ${{ matrix.version }}
actions-cache-folder: '${{ runner.temp }}/xmake-cache'
actions-cache-key: ${{ matrix.version }}-absolute
build-cache: true
build-cache-key: ${{ matrix.version }}-absolute
package-cache: true
package-cache-key: ${{ matrix.version }}-absolute
project-path: 'tests/sample'
- name: Run tests with absolute cache path
run: |
xmake --version
cd tests/sample
xmake -y -vD
xmake run
xmake clean
+58 -9
View File
@@ -11,7 +11,7 @@ See [action.yml](./action.yml).
## Example ## Example
Use latest version: ### Use latest version
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
@@ -19,7 +19,7 @@ with:
xmake-version: latest xmake-version: latest
``` ```
Use specified version: ### Use specified version
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
@@ -27,7 +27,7 @@ with:
xmake-version: '2.5.3' xmake-version: '2.5.3'
``` ```
Use specified branch: ### Use specified branch
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
@@ -35,7 +35,7 @@ with:
xmake-version: branch@master xmake-version: branch@master
``` ```
Use semver: ### Use semver
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
@@ -43,25 +43,74 @@ with:
xmake-version: '>=2.2.6 <=2.5.3' xmake-version: '>=2.2.6 <=2.5.3'
``` ```
Use action cache: ### Cache xmake
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: '2.7.2' xmake-version: '2.9.7'
actions-cache-folder: '.xmake-cache' actions-cache-folder: '.xmake-cache'
``` ```
Use action cache with cachekey: ### Cache xmake with cachekey
```yml ```yml
uses: xmake-io/github-action-setup-xmake@v1 uses: xmake-io/github-action-setup-xmake@v1
with: with:
xmake-version: '2.7.2' xmake-version: '2.9.7'
actions-cache-folder: '.xmake-cache' actions-cache-folder: '.xmake-cache'
actions-cache-key: 'archlinux-ci' 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 ## Contributing
### Prepare development environment ### Prepare development environment
@@ -93,6 +142,6 @@ git branch test
git checkout test git checkout test
pnpm build pnpm build
pnpm release pnpm release
git-commit -a -m "..." git commit -a -m "..."
git push origin test git push origin test
``` ```
+21 -1
View File
@@ -16,6 +16,26 @@ inputs:
actions-cache-key: actions-cache-key:
description: The actions cache key. description: The actions cache key.
default: '' 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: runs:
using: 'node20' using: 'node24'
main: 'dist/index.js' main: 'dist/index.js'
post: 'dist/index.js'
+52677 -55178
View File
File diff suppressed because one or more lines are too long
+95 -49
View File
@@ -1,21 +1,20 @@
{ {
"name": "github-action-setup-xmake", "name": "github-action-setup-xmake",
"version": "1.1.2", "version": "1.2.5",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "github-action-setup-xmake", "name": "github-action-setup-xmake",
"version": "1.1.2", "version": "1.2.5",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"dependencies": { "dependencies": {
"@actions/cache": "^3.2.4", "@actions/cache": "^4.0.3",
"@actions/core": "^1.10.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/io": "^1.1.3", "@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.2",
"pnpm": "^9.15.0", "semver": "^7.7.2"
"semver": "^7.6.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.12", "@types/jest": "^29.5.12",
@@ -36,9 +35,9 @@
} }
}, },
"node_modules/@actions/cache": { "node_modules/@actions/cache": {
"version": "3.3.0", "version": "4.0.3",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.3.0.tgz", "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-4.0.3.tgz",
"integrity": "sha512-+eCsMTIZUEm+QA9GqjollOhCdvRrZ1JV8d9Rp34zVNizBkYITO8dhKczP5Xps1dFzc5n59p7vYVtZrGt18bb5Q==", "integrity": "sha512-SvrqFtYJ7I48A/uXNkoJrnukx5weQv1fGquhs3+4nkByZThBH109KTIqj5x/cGV7JGNvb8dLPVywUOqX1fjiXg==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
@@ -49,6 +48,7 @@
"@azure/abort-controller": "^1.1.0", "@azure/abort-controller": "^1.1.0",
"@azure/ms-rest-js": "^2.6.0", "@azure/ms-rest-js": "^2.6.0",
"@azure/storage-blob": "^12.13.0", "@azure/storage-blob": "^12.13.0",
"@protobuf-ts/plugin": "^2.9.4",
"semver": "^6.3.1" "semver": "^6.3.1"
} }
}, },
@@ -103,22 +103,15 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@actions/tool-cache": { "node_modules/@actions/tool-cache": {
"version": "2.0.1", "version": "2.0.2",
"license": "MIT", "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-2.0.2.tgz",
"integrity": "sha512-fBhNNOWxuoLxztQebpOaWu6WeVmuwa77Z+DxIZ1B+OYvGkGQon6kTVg6Z32Cb13WCuw0szqonK+hh03mJV7Z6w==",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.11.1",
"@actions/exec": "^1.0.0", "@actions/exec": "^1.0.0",
"@actions/http-client": "^2.0.1", "@actions/http-client": "^2.0.1",
"@actions/io": "^1.1.1", "@actions/io": "^1.1.1",
"semver": "^6.1.0", "semver": "^6.1.0"
"uuid": "^3.3.2"
}
},
"node_modules/@actions/tool-cache/node_modules/@actions/exec": {
"version": "1.1.0",
"license": "MIT",
"dependencies": {
"@actions/io": "^1.0.1"
} }
}, },
"node_modules/@actions/tool-cache/node_modules/semver": { "node_modules/@actions/tool-cache/node_modules/semver": {
@@ -128,13 +121,6 @@
"semver": "bin/semver.js" "semver": "bin/semver.js"
} }
}, },
"node_modules/@actions/tool-cache/node_modules/uuid": {
"version": "3.4.0",
"license": "MIT",
"bin": {
"uuid": "bin/uuid"
}
},
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
@@ -1709,6 +1695,83 @@
"url": "https://opencollective.com/unts" "url": "https://opencollective.com/unts"
} }
}, },
"node_modules/@protobuf-ts/plugin": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/@protobuf-ts/plugin/-/plugin-2.10.0.tgz",
"integrity": "sha512-iMX4C4TVfMNRLn2msK0cVg5jmizjtu5FYiy8EK5Lg6EgyR9TVHeK2rzmufWKYM2Pcg1jSwC0cFcXHQnCoeFxUg==",
"license": "Apache-2.0",
"dependencies": {
"@protobuf-ts/plugin-framework": "^2.10.0",
"@protobuf-ts/protoc": "^2.10.0",
"@protobuf-ts/runtime": "^2.10.0",
"@protobuf-ts/runtime-rpc": "^2.10.0",
"typescript": "^3.9"
},
"bin": {
"protoc-gen-dump": "bin/protoc-gen-dump",
"protoc-gen-ts": "bin/protoc-gen-ts"
}
},
"node_modules/@protobuf-ts/plugin-framework": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/@protobuf-ts/plugin-framework/-/plugin-framework-2.10.0.tgz",
"integrity": "sha512-EuW9irbt+w7Ml1CaAxK6xyl7pSuWVbNy0rsChxJEthMrAVTN5EPdJ3whNWvsRBa+HwRImEl8KHNnRoq/vGOHbg==",
"license": "(Apache-2.0 AND BSD-3-Clause)",
"dependencies": {
"@protobuf-ts/runtime": "^2.10.0",
"typescript": "^3.9"
}
},
"node_modules/@protobuf-ts/plugin-framework/node_modules/typescript": {
"version": "3.9.10",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/@protobuf-ts/plugin/node_modules/typescript": {
"version": "3.9.10",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/@protobuf-ts/protoc": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/@protobuf-ts/protoc/-/protoc-2.10.0.tgz",
"integrity": "sha512-S4BtGBh22+uL5E6qLVxV0QNY6tiLVB8QL7RIkvo+KYknipZfSNwubdKy5CPkrwVXzJn4s3cx7bKx1w6BxkBIPg==",
"license": "Apache-2.0",
"bin": {
"protoc": "protoc.js"
}
},
"node_modules/@protobuf-ts/runtime": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/@protobuf-ts/runtime/-/runtime-2.10.0.tgz",
"integrity": "sha512-ypYwGg9Pn3W/2lZ7/HW60hONGuSdzphvOY8Dq7LeNttymDe0y3LaTUUMRpuGqOT6FfrWEMnfQbyqU8AAreo8wA==",
"license": "(Apache-2.0 AND BSD-3-Clause)"
},
"node_modules/@protobuf-ts/runtime-rpc": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/@protobuf-ts/runtime-rpc/-/runtime-rpc-2.10.0.tgz",
"integrity": "sha512-8CS/XPv3+pMK4v8UKhtCdvbS4h9l7aqlteKdRt0/UbIKZ8n0qHj6hX8cBhz2ngvohxCOS0N08zPr9aCLBNhW3Q==",
"license": "Apache-2.0",
"dependencies": {
"@protobuf-ts/runtime": "^2.10.0"
}
},
"node_modules/@sinclair/typebox": { "node_modules/@sinclair/typebox": {
"version": "0.27.8", "version": "0.27.8",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz",
@@ -5094,22 +5157,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/pnpm": {
"version": "9.15.0",
"resolved": "https://registry.npmjs.org/pnpm/-/pnpm-9.15.0.tgz",
"integrity": "sha512-duI3l2CkMo7EQVgVvNZije5yevN3mqpMkU45RBVsQpmSGon5djge4QfUHxLPpLZmgcqccY8GaPoIMe1MbYulbA==",
"license": "MIT",
"bin": {
"pnpm": "bin/pnpm.cjs",
"pnpx": "bin/pnpx.cjs"
},
"engines": {
"node": ">=18.12"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/prelude-ls": { "node_modules/prelude-ls": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
@@ -5415,10 +5462,9 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "7.6.3", "version": "7.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",
"integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
"license": "ISC",
"bin": { "bin": {
"semver": "bin/semver.js" "semver": "bin/semver.js"
}, },
+7 -7
View File
@@ -1,6 +1,6 @@
{ {
"name": "github-action-setup-xmake", "name": "github-action-setup-xmake",
"version": "1.1.2", "version": "1.2.5",
"description": "Set up your GitHub Actions workflow with a specific version of xmake", "description": "Set up your GitHub Actions workflow with a specific version of xmake",
"main": "dist/index.js", "main": "dist/index.js",
"author": "OpportunityLiu", "author": "OpportunityLiu",
@@ -18,12 +18,12 @@
"release": "pnpm clean && pnpm format && pnpm lint && pnpm build" "release": "pnpm clean && pnpm format && pnpm lint && pnpm build"
}, },
"dependencies": { "dependencies": {
"@actions/cache": "^3.2.4", "@actions/cache": "^5.0.5",
"@actions/core": "^1.10.1", "@actions/core": "^2.0.3",
"@actions/exec": "^1.1.1", "@actions/exec": "^2.0.0",
"@actions/io": "^1.1.3", "@actions/io": "^2.0.0",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^3.0.1",
"semver": "^7.6.0" "semver": "^7.7.4"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.12", "@types/jest": "^29.5.12",
+320 -376
View File
File diff suppressed because it is too large Load Diff
+169
View File
@@ -0,0 +1,169 @@
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 path from 'path';
import * as fsutils from './fsutils';
import { getPlatformIdentifier } from './system';
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;
}
async function getBuildCacheKey(buildCacheTime?: string): Promise<string> {
let buildCacheKey = core.getInput('build-cache-key');
if (!buildCacheKey) {
buildCacheKey = '';
}
if (!buildCacheTime || buildCacheTime === '') {
buildCacheTime = getBuildTime();
}
const platformIdentifier = await getPlatformIdentifier();
return `xmake-build-cache-${buildCacheKey}-${buildCacheTime}-${platformIdentifier}`;
}
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.env = {
...process.env,
XMAKE_ROOT: 'y',
};
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 = await 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 = await 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,
});
const options: ExecOptions = {};
options.env = {
...process.env,
XMAKE_ROOT: 'y',
};
await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'build_cache_saved.txt')], options);
await cache.saveCache([buildCacheFolder], buildCacheKey);
}
}
+22
View File
@@ -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;
}
}
+31 -16
View File
@@ -3,6 +3,7 @@ import * as io from '@actions/io';
import * as os from 'os'; import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
import { Sha, RefDic, Repo } from './interfaces'; import { Sha, RefDic, Repo } from './interfaces';
import { valid as isValidSemver } from 'semver';
function makeOpt(ref: Sha): { cwd: string } { function makeOpt(ref: Sha): { cwd: string } {
return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) }; return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) };
@@ -20,24 +21,38 @@ export async function lsRemote(repo: Repo): Promise<RefDic> {
}); });
const data: RefDic = { heads: {}, tags: {}, pull: {} }; const data: RefDic = { heads: {}, tags: {}, pull: {} };
out.split('\n').forEach((line) => { out.split('\n').forEach((line) => {
const [ref, tag] = line.trim().split('\t'); const [ref, path] = line.trim().split('\t') as [Sha, string];
if (ref && tag?.startsWith('refs/')) { if (ref && path?.startsWith('refs/')) {
const tagPath = tag.split('/').splice(1); const tagPath = path.split('/').splice(1);
// eslint-disable-next-line @typescript-eslint/no-explicit-any switch (tagPath[0]) {
let ldata = data as any; // eslint-disable-line @typescript-eslint/no-unsafe-assignment case 'heads': {
for (let i = 0; i < tagPath.length - 1; i++) { // refs/heads/copilot/fix-6807
const seg = tagPath[i]; const head = tagPath.slice(1).join('/');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access data.heads[head] = ref;
if (typeof ldata[seg] === 'object') { break;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata = ldata[seg]; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata = ldata[seg] = {};
} }
case 'pull': {
// refs/pull/11/head
// refs/pull/11/merge
const pr = Number(tagPath[1]);
if (!data.pull[pr]) {
data.pull[pr] = {} as RefDic['pull'][number];
}
data.pull[pr][tagPath[2] as 'head' | 'merge'] = ref;
break;
}
case 'tags': {
// refs/tags/preview
// refs/tags/v3.0.3
const tag = tagPath.slice(1).join('/');
if (isValidSemver(tag)) {
data.tags[tag] = ref;
}
break;
}
default:
break;
} }
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata[tagPath[tagPath.length - 1]] = ref;
} }
}); });
return data; return data;
+22 -14
View File
@@ -1,24 +1,32 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import { exec } from '@actions/exec'; import * as stateHelper from './state-helper';
import * as os from 'os'; import { installXmake } from './install';
import { selectVersion } from './versions'; import { loadBuildCache, saveBuildCache } from './build-cache';
import { winInstall } from './win-install'; import { loadPackageCache, savePackageCache } from './package-cache';
import { unixInstall } from './unix-install';
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
const version = await selectVersion(); await installXmake();
if (os.platform() === 'win32' || os.platform() === 'cygwin') { await loadBuildCache();
const latest = await selectVersion('latest'); await loadPackageCache();
await winInstall(version, latest);
} else {
await unixInstall(version);
}
await exec('xmake --root --version');
} catch (error) { } catch (error) {
const ex = error as Error; const ex = error as Error;
core.setFailed(ex.message); core.setFailed(ex.message);
} }
} }
run().catch((e: Error) => 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));
}
+15
View File
@@ -0,0 +1,15 @@
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') {
await winInstall(version);
} else {
await unixInstall(version);
}
await exec('xmake --root --version');
}
+132
View File
@@ -0,0 +1,132 @@
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 path from 'path';
import * as fsutils from './fsutils';
import { getPlatformIdentifier } from './system';
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.env = {
...process.env,
XMAKE_ROOT: 'y',
};
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();
}
const platformIdentifier = await getPlatformIdentifier();
return `xmake-package-cache-${packageCacheKey}-${packageCacheHash}-${platformIdentifier}`;
}
async function getPackageCachePath(): Promise<string> {
let packageCachePath = '';
const options: ExecOptions = {};
options.env = {
...process.env,
XMAKE_ROOT: 'y',
};
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,
});
const options: ExecOptions = {};
options.env = {
...process.env,
XMAKE_ROOT: 'y',
};
await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'package_cache_saved.txt')], options);
await cache.saveCache([packageCacheFolder], packageCacheKey);
}
}
+12
View File
@@ -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');
}
+28
View File
@@ -0,0 +1,28 @@
import * as core from '@actions/core';
import { exec } from '@actions/exec';
import * as os from 'os';
export async function getPlatformIdentifier(): Promise<string> {
let identifier = `${os.platform()}-${os.arch()}-${process.env.RUNNER_OS ?? 'unknown'}`;
if (os.platform() === 'darwin') {
let productVersion = '';
try {
await exec('sw_vers', ['-productVersion'], {
silent: true,
listeners: {
stdout: (data: Buffer) => {
productVersion = data.toString().trim();
},
},
});
if (productVersion) {
identifier += `-${productVersion}`;
}
} catch (error: unknown) {
core.warning(
`Failed to get macOS product version: ${error instanceof Error ? error.message : String(error)}`,
);
}
}
return identifier;
}
+6 -6
View File
@@ -9,6 +9,7 @@ import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as git from './git'; import * as git from './git';
import { Version } from './interfaces'; import { Version } from './interfaces';
import { getPlatformIdentifier } from './system';
async function install(sourceDir: string, binDir: string): Promise<void> { async function install(sourceDir: string, binDir: string): Promise<void> {
if (fs.existsSync(path.join(sourceDir, 'configure'))) { if (fs.existsSync(path.join(sourceDir, 'configure'))) {
@@ -32,12 +33,11 @@ export async function unixInstall(version: Version): Promise<void> {
if (version.type !== 'local') { if (version.type !== 'local') {
const ver = version.version; const ver = version.version;
const sha = version.sha; const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${ const platformIdentifier = await getPlatformIdentifier();
process.env.RUNNER_OS ?? 'unknown' const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
}`;
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) { if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder); const fullCachePath = path.resolve(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
try { try {
try { try {
fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK); fs.accessSync(path.join(fullCachePath, 'bin', 'xmake'), fs.constants.X_OK);
@@ -48,7 +48,7 @@ export async function unixInstall(version: Version): Promise<void> {
toolDir = fullCachePath; toolDir = fullCachePath;
core.info(`cache path: ${toolDir}, key: ${cacheKey}`); 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}, key: ${cacheKey}".`);
await io.rmRF(fullCachePath); await io.rmRF(fullCachePath);
} }
} else { } else {
@@ -65,7 +65,7 @@ export async function unixInstall(version: Version): Promise<void> {
let cacheDir = ''; let cacheDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) { if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
cacheDir = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder); cacheDir = path.resolve(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
await io.cp(binDir, cacheDir, { await io.cp(binDir, cacheDir, {
recursive: true, recursive: true,
}); });
+8 -8
View File
@@ -96,11 +96,11 @@ async function selectSha(repo: Repo, sha: string): Promise<Version> {
} }
} }
return Promise.resolve( return Promise.resolve(
new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`), new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substring(0, 8)}`),
); );
} }
export async function selectVersion(version?: string): Promise<Version> { export async function selectVersion(version?: string, _fallback: boolean = false): Promise<Version> {
// get version string // get version string
version = (version ?? core.getInput('xmake-version')) || 'latest'; version = (version ?? core.getInput('xmake-version')) || 'latest';
if (version.toLowerCase() === 'latest') version = ''; if (version.toLowerCase() === 'latest') version = '';
@@ -123,20 +123,20 @@ export async function selectVersion(version?: string): Promise<Version> {
// select branch // select branch
if (version.startsWith('branch@')) { if (version.startsWith('branch@')) {
const branch = version.substr('branch@'.length); const branch = version.substring('branch@'.length);
ret = await selectBranch(repo, branch); ret = await selectBranch(repo, branch);
} }
// select pr // select pr
if (version.startsWith('pr@')) { if (version.startsWith('pr@')) {
const pr = Number.parseInt(version.substr('pr@'.length)); const pr = Number.parseInt(version.substring('pr@'.length));
if (Number.isNaN(pr) || pr <= 0) { if (Number.isNaN(pr) || pr <= 0) {
throw new Error(`Invalid pull requrest ${version.substr('pr@'.length)}, should be a positive integer`); throw new Error(`Invalid pull requrest ${version.substring('pr@'.length)}, should be a positive integer`);
} }
ret = await selectPr(repo, pr); ret = await selectPr(repo, pr);
} }
// select sha // select sha
if (version.startsWith('sha@')) { if (version.startsWith('sha@')) {
const sha = version.substr('sha@'.length); const sha = version.substring('sha@'.length);
ret = await selectSha(repo, sha); ret = await selectSha(repo, sha);
} }
// select version // select version
@@ -148,9 +148,9 @@ export async function selectVersion(version?: string): Promise<Version> {
} }
if (ret.type === 'local') { if (ret.type === 'local') {
core.info(`Use local xmake at '${ret.path}'`); core.info(`Use local xmake at '${ret.path}'`);
} else { } else if (!_fallback) {
core.info( core.info(
`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + `Selected xmake ${String(ret)} (commit: ${ret.sha.substring(0, 8)})` +
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''), (repo !== DEFAULT_REPO ? ` of ${repo}` : ''),
); );
} }
+40 -17
View File
@@ -9,14 +9,22 @@ import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as git from './git'; import * as git from './git';
import { Version, GitVersion } from './interfaces'; import { Version, GitVersion } from './interfaces';
import { selectVersion } from './versions';
import { getPlatformIdentifier } from './system';
function getInstallerUrl(version: GitVersion, latest: GitVersion): string { async function getInstallerUrl(version: GitVersion, _fallback: boolean = false): Promise<string> {
const ver = version.version; const latest = (await selectVersion('latest', _fallback)) as GitVersion;
const latestVers = latest.version;
let vers = version.version;
let finalUrl: string;
switch (version.type) { switch (version.type) {
case 'heads': { case 'heads': {
const arch = os.arch() === 'x64' ? 'win64' : 'win32'; const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
const latestver = latest.version; if (vers !== 'dev' && vers !== 'master') {
return `https://github.com/xmake-io/xmake/releases/download/${latestver}/xmake-${ver}.${arch}.exe`; vers = latestVers;
}
finalUrl = `https://github.com/xmake-io/xmake/releases/download/${latestVers}/xmake-${vers}.${arch}.exe`;
break;
} }
case 'pull': { case 'pull': {
throw new Error('PR builds for windows is not supported'); throw new Error('PR builds for windows is not supported');
@@ -25,10 +33,11 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
throw new Error('Sha builds for windows is not supported'); throw new Error('Sha builds for windows is not supported');
} }
case 'tags': { case 'tags': {
const arch = os.arch() === 'x64' ? 'win64' : 'win32'; const arch = os.arch() === 'arm64' ? 'arm64' : os.arch() === 'x64' ? 'win64' : 'win32';
return semver.gt(ver, '2.2.6') finalUrl = semver.gt(vers, '2.2.6')
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe` ? `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.${arch}.exe`
: `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`; : `https://github.com/xmake-io/xmake/releases/download/${vers}/xmake-${vers}.exe`;
break;
} }
default: { default: {
// check that we have tested all types // check that we have tested all types
@@ -36,6 +45,21 @@ function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
throw new Error('Unknown version type'); throw new Error('Unknown version type');
} }
} }
// check if the URL returns 404. If so, xmake may have just released a
// new version, causing some binaries to be temporarily unavailable, so
// we need to fallback to the previous version.
if (!_fallback) {
const head = await fetch(finalUrl, { method: 'HEAD' });
if (head.status === 404) {
const currentVers = latestVers || vers;
const previousVersion = (await selectVersion('<' + currentVers)) as GitVersion;
core.warning(
`The requested version ${currentVers} (${finalUrl}) resource is temporarily unavailable, trying to fallback to the previous version...`,
);
return await getInstallerUrl(previousVersion, true);
}
}
return finalUrl;
} }
async function installFromSource(xmakeBin: string, sourceDir: string, binDir: string): Promise<void> { async function installFromSource(xmakeBin: string, sourceDir: string, binDir: string): Promise<void> {
@@ -43,8 +67,8 @@ async function installFromSource(xmakeBin: string, sourceDir: string, binDir: st
await exec(xmakeBin, ['install', '-o', binDir, 'cli'], { 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): Promise<void> {
if (version.type === 'local' || latest.type === 'local') { if (version.type === 'local') {
throw new Error('Local builds for windows is not supported'); throw new Error('Local builds for windows is not supported');
} }
@@ -56,13 +80,12 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
const ver = version.version; const ver = version.version;
const sha = version.sha; const sha = version.sha;
const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${os.arch()}-${os.platform()}-${ const platformIdentifier = await getPlatformIdentifier();
process.env.RUNNER_OS ?? 'unknown' const cacheKey = `xmake-cache-${actionsCacheKey}-${ver}-${sha}-${platformIdentifier}`;
}`;
let toolDir = ''; let toolDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) { if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder); const fullCachePath = path.resolve(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
try { try {
try { try {
fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK); fs.accessSync(path.join(fullCachePath, 'xmake.exe'), fs.constants.X_OK);
@@ -82,7 +105,7 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
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 = await getInstallerUrl(version);
core.info(`downloading from ${url}`); core.info(`downloading from ${url}`);
const file = await toolCache.downloadTool(url); const file = await toolCache.downloadTool(url);
const exe = path.format({ const exe = path.format({
@@ -123,7 +146,7 @@ export async function winInstall(version: Version, latest: Version): Promise<voi
if (toolDir) { if (toolDir) {
let cacheDir = ''; let cacheDir = '';
if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) { if (actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
cacheDir = path.join(process.env.GITHUB_WORKSPACE, actionsCacheFolder); cacheDir = path.resolve(process.env.GITHUB_WORKSPACE, actionsCacheFolder);
await io.cp(toolDir, cacheDir, { await io.cp(toolDir, cacheDir, {
recursive: true, recursive: true,
}); });
+8
View File
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/
# MacOS Cache
.DS_Store
+6
View File
@@ -0,0 +1,6 @@
#include <iostream>
int main(int argc, char** argv) {
std::cout << "hello world!" << std::endl;
return 0;
}
+9
View File
@@ -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")