Transition to GitHub Actions (#136)

* gulpfile.js: fix ESLint warnings

* package.json: add shortcut scripts

* scripts/games: do a shallow git clone to save time

* ci: migrate to GitHub Actions
This commit is contained in:
liushuyu 2020-11-05 00:53:06 -07:00 committed by GitHub
parent 5dc5d4331a
commit 245eaf7448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 88 deletions

44
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,44 @@
name: Deploy Site
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Install dependencies
run: |
echo '========== Installing gulp & dependencies =========='
sudo apt-get install graphicsmagick
wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.52/hugo_0.52_Linux-64bit.deb
sudo dpkg -i hugo.deb
yarn install
# Install dependencies one-by-one to avoid race-conditions
pushd ./scripts/wiki/ && yarn && popd
pushd ./scripts/games/ && yarn && popd
hugo version
- name: Build
env:
TENANT: 'citra'
run: |
echo '========== Starting gulp deploy task =========='
yarn run build
- name: Deploy
if: ${{ (! github.base_ref) && (github.repository == 'citra-emu/citra-web') }}
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY_NAME: CitraBotWeb/CitraBotWeb.github.io
BRANCH: master
FOLDER: build
CLEAN: true
SINGLE_COMMIT: true

View File

@ -1,32 +0,0 @@
# Build status located at https://travis-ci.org/citra-emu/citra-web
language: node_js
node_js:
- "lts/erbium"
cache: yarn
script:
- echo '========== Updating Yarn ==========================='
- curl -o- -L https://yarnpkg.com/install.sh | bash
- echo '========== Installing gulp & dependencies =========='
- sudo apt-get install graphicsmagick
- wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.52/hugo_0.52_Linux-64bit.deb
- sudo dpkg -i hugo.deb
- yarn install
- echo '========== Starting gulp deploy task =========='
- hugo version
- yarn run gulp all --production
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
local_dir: build
repo: CitraBotWeb/CitraBotWeb.github.io
target_branch: master
fqdn: citra-emu.org
on:
branch: master
notifications:
email:
- citra@citra-emu.org

View File

@ -1,3 +1,4 @@
/* eslint-disable no-console */
const gulp = require('gulp');
const fs = require('fs');
const util = require('gulp-util');
@ -11,69 +12,69 @@ const concat = require('gulp-concat');
const imageResize = require('gulp-image-resize');
gulp.task('scripts:games', function (callback) {
exec(`cd ./scripts/games/ && yarn install && node app.js`, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
exec('yarn install && node app.js', { cwd: './scripts/games/' }, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
});
gulp.task('scripts:wiki', function (callback) {
exec(`cd ./scripts/wiki/ && yarn install && node app.js`, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
exec('yarn install && node app.js', { cwd: './scripts/wiki/' }, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
});
gulp.task('assets:images', function() {
var baseImages = gulp.src(`build/images/*`, {base: './'})
.pipe(gulp.dest('./'));
var jumbotronImages = gulp.src(`build/images/jumbotron/*`, {base: './'})
.pipe(imageResize({ width: 786, height: 471, crop: true }))
.pipe(gulp.dest('./'));
var bannerImages = gulp.src(`build/images/banners/*`, {base: './'})
.pipe(imageResize({ width: 824, height: 306, crop: false }))
.pipe(gulp.dest('./'));
var boxartImages = gulp.src(`build/images/game/boxart/*`, {base: './'})
.pipe(imageResize({ width: 328, height: 300, crop: true }))
.pipe(gulp.dest('./'));
var iconImages = gulp.src(`build/images/game/icons/*`, {base: './'})
.pipe(imageResize({ width: 48, height: 48, crop: true }))
.pipe(gulp.dest('./'));
var screenshotImages = gulp.src(`build/images/screenshots/*`)
.pipe(imageResize({ width: 400, height: 240, crop: false }))
.pipe(gulp.dest(`build/images/screenshots/thumbs`));
var baseImages = gulp.src('build/images/*', {base: './'})
.pipe(gulp.dest('./'));
var jumbotronImages = gulp.src('build/images/jumbotron/*', {base: './'})
.pipe(imageResize({ width: 786, height: 471, crop: true }))
.pipe(gulp.dest('./'));
var bannerImages = gulp.src('build/images/banners/*', {base: './'})
.pipe(imageResize({ width: 824, height: 306, crop: false }))
.pipe(gulp.dest('./'));
var boxartImages = gulp.src('build/images/game/boxart/*', {base: './'})
.pipe(imageResize({ width: 328, height: 300, crop: true }))
.pipe(gulp.dest('./'));
var iconImages = gulp.src('build/images/game/icons/*', {base: './'})
.pipe(imageResize({ width: 48, height: 48, crop: true }))
.pipe(gulp.dest('./'));
var screenshotImages = gulp.src('build/images/screenshots/*')
.pipe(imageResize({ width: 400, height: 240, crop: false }))
.pipe(gulp.dest('build/images/screenshots/thumbs'));
return merge(baseImages, jumbotronImages, bannerImages, boxartImages, iconImages, screenshotImages);
return merge(baseImages, jumbotronImages, bannerImages, boxartImages, iconImages, screenshotImages);
});
gulp.task('assets:js', function() {
return gulp.src(['src/js/**/*.js'])
.pipe(concat('script.js'))
.pipe(gulp.dest('build/js'));
return gulp.src(['src/js/**/*.js'])
.pipe(concat('script.js'))
.pipe(gulp.dest('build/js'));
});
gulp.task('assets:fonts', function(){
return gulp.src('./node_modules/bootstrap-sass/assets/fonts/**/*')
.pipe(gulp.dest('build/fonts/'));
return gulp.src('./node_modules/bootstrap-sass/assets/fonts/**/*')
.pipe(gulp.dest('build/fonts/'));
});
gulp.task('assets:scss', function () {
var postCssOptions = [ cssnano ];
return gulp.src('src/scss/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss(postCssOptions))
.pipe(gulp.dest('build/css'))
.pipe(browserSync.stream());
var postCssOptions = [ cssnano ];
return gulp.src('src/scss/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss(postCssOptions))
.pipe(gulp.dest('build/css'))
.pipe(browserSync.stream());
});
gulp.task('hugo', function (cb) {
exec('hugo -s ./site/ -d ../build/ -v', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
exec('hugo -s ./site/ -d ../build/ -v', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('final:serve', function(done) {
@ -90,29 +91,29 @@ gulp.task('final:serve', function(done) {
gulp.watch('site/**/*.md', gulp.series('hugo'));
gulp.watch('build/**/*').on('change', function(x) {
browserSync.reload(x);
browserSync.reload(x);
});
done();
});
gulp.task('final:publish', function(done) {
fs.writeFileSync(`build/CNAME`, `${cname}`);
fs.writeFileSync(`build/robots.txt`, `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
done();
fs.writeFileSync('build/CNAME', `${cname}`);
fs.writeFileSync('build/robots.txt', `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
done();
});
const cname = 'citra-emu.org';
var finalCommand = null;
if (util.env.production) {
process.env.HUGO_ENV = 'PRD';
process.env.HUGO_BASEURL = `https://${cname}`;
finalCommand = 'final:publish';
process.env.HUGO_ENV = 'PRD';
process.env.HUGO_BASEURL = `https://${cname}`;
finalCommand = 'final:publish';
} else {
process.env.HUGO_ENV = 'DEV';
process.env.HUGO_BASEURL = 'http://localhost:3000';
finalCommand = 'final:serve';
process.env.HUGO_ENV = 'DEV';
process.env.HUGO_BASEURL = 'http://localhost:3000';
finalCommand = 'final:serve';
}
util.log(`process.env.HUGO_ENV = '${process.env.HUGO_ENV}'`);
@ -120,4 +121,4 @@ util.log(`process.env.HUGO_BASEURL = '${process.env.HUGO_BASEURL}'`);
gulp.task('default', gulp.series(gulp.parallel('assets:js', 'assets:fonts', 'assets:scss'), 'hugo', 'assets:images', finalCommand));
gulp.task('all', gulp.series(gulp.parallel('scripts:games', 'scripts:wiki'), gulp.parallel('assets:js', 'assets:fonts', 'assets:scss'), 'hugo', 'assets:images', finalCommand));
gulp.task('content', gulp.series('hugo', finalCommand));
gulp.task('content', gulp.series('hugo', finalCommand));

View File

@ -4,6 +4,10 @@
"description": "The Citra Official Website",
"author": "",
"license": "AGPL-3.0-only",
"scripts": {
"build": "gulp all --production",
"serve": "gulp all"
},
"dependencies": {
"bootstrap-sass": "^3.4.1",
"browser-sync": "^2.26.7",

View File

@ -38,7 +38,7 @@ function gitPull(directory, repository) {
} else {
logger.info(`Cloning repository from Github : ${directory}`);
logger.info(`git clone ${repository}`);
exec(`git clone ${repository}`);
exec(`git clone --depth=1 ${repository}`);
}
}