Skip to content

Commit 820eb37

Browse files
committed
feat: support type 'actions'
1 parent 2d0bf4b commit 820eb37

7 files changed

Lines changed: 202 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22

33
package-lock.json
44
samples/**/.travis.yml
5-
samples/**/appveyor.yml
5+
samples/**/appveyor.yml
6+
samples/**/.github

generator.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ config.travis_services = arrayify(config.travis_services);
5252
let ymlName = '';
5353

5454
for (const type of config.types) {
55+
if (type === 'actions') {
56+
;[
57+
'.github/workflows/run-ci.yml',
58+
'.github/workflows/set-env-vars.sh',
59+
].forEach(file => {
60+
const srcpath = path.resolve(__dirname, 'tpl', file);
61+
const targetpath = path.resolve(root, file);
62+
63+
let content = fs.readFileSync(srcpath, 'utf8');
64+
content = engine.renderString(content, config);
65+
66+
fs.mkdirSync(path.dirname(targetpath), { recursive: true });
67+
fs.writeFileSync(targetpath, content);
68+
console.log(`[fibjs-ci] create ${targetpath} success`);
69+
})
70+
71+
continue ;
72+
}
73+
5574
if (type === 'travis') {
5675
ymlName = '.travis.yml';
5776
} else if (type === 'appveyor') {

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
"homepage": "https://github.com/fibjs-modules/ci#readme",
1919
"dependencies": {
2020
"nunjucks": "^3.0.0"
21-
}
21+
},
22+
"files": [
23+
"generator.js",
24+
"tpl"
25+
]
2226
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "normal-actions-only",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"ci": {
11+
"type": "actions"
12+
},
13+
"license": "ISC",
14+
"dependencies": {
15+
"@fibjs/ci": "file:../.."
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "normal-actions-versions",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"ci": {
11+
"type": "actions",
12+
"version": [
13+
"0.21.0",
14+
"0.22.0",
15+
"0.26.1"
16+
]
17+
},
18+
"license": "ISC",
19+
"dependencies": {
20+
"@fibjs/ci": "file:../.."
21+
}
22+
}

tpl/.github/workflows/run-ci.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{% raw %}name: run ci for fibjs
2+
3+
on:
4+
push:
5+
branches:
6+
- 'ci/**'
7+
- 'ci-**'
8+
- 'releases/**'
9+
- 'feat/**'
10+
- 'bugfix/**'
11+
- 'dev'
12+
- 'master'
13+
- 'test_ci'
14+
tags:
15+
- v*.*.*
16+
- test_github_actions_*
17+
pull_request:
18+
branches:
19+
- 'dev'
20+
21+
jobs:
22+
build:
23+
runs-on: ${{ matrix.os }}
24+
continue-on-error: true
25+
strategy:
26+
matrix:
27+
os: [ubuntu-16.04]
28+
version: [{% endraw %}{{ versions.join(', ') }}{% raw %}]
29+
arch: [amd64, i386]
30+
include:
31+
- os: windows-2016
32+
arch: amd64
33+
- os: macos-10.15
34+
arch: amd64
35+
36+
steps:
37+
- name: Check out Git repository
38+
uses: actions/checkout@v2
39+
with:
40+
submodules: 'recursive'
41+
42+
- name: Set Env Variables
43+
id: set-env-vars
44+
shell: bash
45+
run: |
46+
bash .github/workflows/set-env-vars.sh
47+
env:
48+
ARCH: ${{ matrix.arch }}
49+
OS: ${{ matrix.os }}
50+
51+
- name: Install FIBJS
52+
shell: bash
53+
run: |
54+
npm i;
55+
mkdir -p ./node_modules/.bin;
56+
rm -rf ./node_modules/.bin/fibjs;
57+
if [[ "$RUNNER_OS" != "Windows" ]]; then
58+
curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.xz" -o ./node_modules/.bin/fibjs.xz;
59+
xz -d ./node_modules/.bin/fibjs.xz;
60+
chmod a+x ./node_modules/.bin/fibjs;
61+
else
62+
curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-windows-${FIBJS_ARCH}.exe" -o ./node_modules/.bin/fibjs.exe;
63+
fi
64+
env:
65+
FIBJS_OS: ${{ steps.set-env-vars.outputs.FIBJS_OS }}
66+
FIBJS_ARCH: ${{ steps.set-env-vars.outputs.FIBJS_ARCH }}
67+
FIBJS_VERSION: ${{ matrix.version }}
68+
69+
- name: Run CI
70+
shell: bash
71+
run: |
72+
npm install;
73+
./node_modules/.bin/lerna bootstrap;
74+
npm run ci;
75+
env:
76+
FIBJS_OS: ${{ steps.set-env-vars.outputs.FIBJS_OS }}
77+
GIT_BRANCH: ${{ steps.set-env-vars.outputs.GIT_BRANCH }}
78+
RELEASE_TAG: ${{ steps.set-env-vars.outputs.RELEASE_TAG }}
79+
GIT_TAG: ${{ steps.set-env-vars.outputs.GIT_TAG }}
80+
{% endraw %}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{% raw %}export GIT_BRANCH=${GITHUB_REF#refs/heads/}
2+
echo "::set-output name=GIT_BRANCH::$GIT_BRANCH"
3+
export GIT_TAG=$(git tag | grep $(git describe --tags HEAD))
4+
echo "::set-output name=GIT_TAG::$GIT_TAG"
5+
export GIT_COMMIT_HEAD_MSG=$(git log --format=%b -1)
6+
echo "::set-output name=GIT_COMMIT_HEAD_MSG::$GIT_COMMIT_HEAD_MSG"
7+
export GIT_COMMIT_SHORTCUTS=$(git log --format=%h -1)
8+
echo "::set-output name=GIT_COMMIT_SHORTCUTS::$GIT_COMMIT_SHORTCUTS"
9+
export GIT_COMMIT_TIME=$(git show -s --format="%cd" --date=format:%Y%m%d%H%M%S HEAD)
10+
echo "::set-output name=GIT_COMMIT_TIME::$GIT_COMMIT_TIME"
11+
12+
if [[ "$GIT_TAG" =~ ^v?[012]\.[0-9]+\.[0-9]+$ ]]; then
13+
export IS_GIT_TAG_MATCH_SEMVER="true"
14+
echo "::set-output name=IS_GIT_TAG_MATCH_SEMVER::$IS_GIT_TAG_MATCH_SEMVER"
15+
fi
16+
17+
if [ -z "$GIT_TAG" ]; then
18+
export RELEASE_TAG="$GIT_COMMIT_TIME-$GIT_COMMIT_SHORTCUTS";
19+
else
20+
export RELEASE_TAG="$GIT_TAG";
21+
fi
22+
if [ -z "$IS_GIT_TAG_MATCH_SEMVER" ]; then
23+
SUFFIX=${GIT_BRANCH//\//'-'}
24+
RELEASE_TAG="$RELEASE_TAG-$SUFFIX"
25+
fi
26+
echo "::set-output name=RELEASE_TAG::$RELEASE_TAG";
27+
28+
case "${RUNNER_OS}" in
29+
Windows)
30+
export FIBJS_OS=windows
31+
;;
32+
macOS)
33+
export FIBJS_OS=darwin
34+
;;
35+
Linux)
36+
export FIBJS_OS=linux
37+
;;
38+
*)
39+
echo "unsupported RUNNER_OS ${RUNNER_OS}";
40+
exit 1
41+
;;
42+
esac
43+
echo "::set-output name=FIBJS_OS::$FIBJS_OS";
44+
45+
case "${ARCH}" in
46+
i386)
47+
export FIBJS_ARCH=x86
48+
;;
49+
amd64)
50+
export FIBJS_ARCH=x64
51+
;;
52+
*)
53+
export FIBJS_ARCH=$ARCH
54+
;;
55+
esac
56+
echo "::set-output name=FIBJS_ARCH::$FIBJS_ARCH";
57+
{% endraw %}

0 commit comments

Comments
 (0)