Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f #25

Open
wants to merge 14 commits into
base: test
Choose a base branch
from
Open

f #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
# Hello world JavaScript action
# Cache Wrt Build action

This action prints "Hello World" or "Hello" + the name of a person to greet to the log. To learn how this action was built, see "[Creating a JavaScript action](https://help.github.com/en/articles/creating-a-javascript-action)" in the GitHub Help documentation.
This action caches builds to speed up openwrt compilation.

## Inputs

### `who-to-greet`
### `ccache`

**Required** The name of the person to greet. Default `"World"`.
Check if to cache ccache. Default `'false'`.

## Outputs
### `toolchain`

### `time`
Check if to cache toolchain. Default `'true'`.

The time we greeted you.
### `skip`

Check if to skip the compilation of toolchain. Default `'true'`.

### `clean`

Set to clean cache. Default `'false'`.

### `prefix`

Path prefix to openwrt build directory. Default `''`.

### `mixkey`

Mix a key to identify a cache when you build openwrt for different architecture. Default `''`.

### `skip_saving`

Skip saving. Default `'false'`.

## Output

### `hit`

Indicate cache found.

## Example usage

```yaml
uses: actions/hello-world-javascript-action@main
uses: klever1988/cachewrtbuild@main
with:
who-to-greet: 'Mona the Octocat'
ccache: 'true'
mixkey: 'ramips'
prefix: 'openwrt'
```
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Hello World'
name: 'Cache Wrt Build'
description: 'Cache builds to speed up openwrt compilation'
inputs:
ccache:
Expand All @@ -25,11 +25,15 @@ inputs:
description: 'mix a key to identify a cache when you build openwrt for different architecture'
required: false
defalut: ''
skip_saving:
description: 'skip saving'
required: false
defalut: false
outputs:
hit:
description: 'indicate cache found'
runs:
using: 'node12'
using: 'node20'
main: 'fetch.js'
post: 'save.js'
post-if: 'success()'
Expand Down
99 changes: 53 additions & 46 deletions fetch.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
const core = require('@actions/core');
const github = require('@actions/github');
const execSync = require('child_process').execSync;
const core = require("@actions/core");
const execSync = require("child_process").execSync;

try {
var paths = new Array();
var keyString = core.getInput('mixkey')+'cache-openwrt';
var restoreKeys = new Array();
const prefix = core.getInput('prefix');
if ( prefix != '' ){
process.chdir(prefix);
}

const toolchain = core.getInput('toolchain');
var skiptoolchain = core.getInput('skip');
if ( toolchain == 'true' ){
stdout = execSync('git log --pretty=tformat:"%h" -n1 tools toolchain').toString().trim();
//restoreKeys.unshift(keyString);
keyString = keyString+'-'+stdout;
paths.push('staging_dir/host*');
paths.push('staging_dir/tool*');
}else{
skiptoolchain = false;
}
var paths = new Array();
var mixkey = core.getInput("mixkey");
var keyString = mixkey ? mixkey + "-cache-openwrt" : "cache-openwrt";
var restoreKeys = new Array();
const prefix = core.getInput("prefix");
if (prefix != "") {
process.chdir(prefix);
}

const ccache = core.getInput('ccache');
if ( ccache == 'true' ){
stdout = execSync('date +%s').toString().trim();
restoreKeys.unshift(keyString);
keyString = keyString+'-'+stdout;
paths.push('.ccache');
}
const toolchain = core.getInput("toolchain");
var skiptoolchain = core.getInput("skip");
if (toolchain == "true") {
stdout = execSync('git log --pretty=tformat:"%h" -n1 tools toolchain')
.toString()
.trim();
//restoreKeys.unshift(keyString);
keyString = keyString + "-" + stdout;
paths.push("staging_dir/host*");
paths.push("staging_dir/tool*");
} else {
skiptoolchain = false;
}

const cache = require('@actions/cache');
const clean = core.getInput('clean');
if ( clean == 'true' ) return;
console.log(keyString, restoreKeys);
const cacheKey = cache.restoreCache(paths, keyString, restoreKeys)
.then(res =>{
if ( typeof res !== 'undefined' && res ){
console.log(res,' cache fetched!');
core.setOutput("hit", '1');
if ( skiptoolchain == 'true' ){
console.log('skiped');
execSync('sed -i \'s/ $(tool.*\\/stamp-compile)//;\' Makefile');
execSync('sed -i \'s/ $(tool.*\\/stamp-install)//;\' Makefile');
//execSync('bash -c \'find build_dir\/{host*,toolchain-*} -name .built\\* -exec touch {} \\;; touch staging_dir\/{host*,toolchain-*}\/stamp\/.*\'');
}
const ccache = core.getInput("ccache");
if (ccache == "true") {
stdout = execSync("date +%s").toString().trim();
restoreKeys.unshift(keyString);
keyString = keyString + "-" + stdout;
paths.push(".ccache");
}
})

const cache = require("@actions/cache");
const clean = core.getInput("clean");
if (clean == "true") return;
console.log(keyString, restoreKeys);
const cacheKey = cache
.restoreCache(paths, keyString, restoreKeys)
.then((res) => {
if (typeof res !== "undefined" && res) {
console.log(res, " cache fetched!");
core.setOutput("hit", "1");
core.saveState("CACHE_STATE", "hit");
if (skiptoolchain == "true") {
console.log("skiped");
execSync(
"sed -i 's/ $(tool.*\\/stamp-compile)//;' Makefile"
);
execSync(
"sed -i 's/ $(tool.*\\/stamp-install)//;' Makefile"
);
//execSync('bash -c \'find build_dir\/{host*,toolchain-*} -name .built\\* -exec touch {} \\;; touch staging_dir\/{host*,toolchain-*}\/stamp\/.*\'');
}
}
});
} catch (error) {
core.setFailed(error.message);
core.setFailed(error.message);
}
2 changes: 1 addition & 1 deletion node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion node_modules/.bin/which

This file was deleted.

Loading
Loading