From 245eaf744889f7baf8a0eeccf9bcd68eacfac4c6 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Thu, 5 Nov 2020 00:53:06 -0700 Subject: [PATCH] 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 --- .github/workflows/deploy.yml | 44 ++++++++++++++ .travis.yml | 32 ---------- gulpfile.js | 111 ++++++++++++++++++----------------- package.json | 4 ++ scripts/games/app.js | 2 +- 5 files changed, 105 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/deploy.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..768c5a4 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2b6fe10..0000000 --- a/.travis.yml +++ /dev/null @@ -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 diff --git a/gulpfile.js b/gulpfile.js index adc41f4..d0b443b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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)); \ No newline at end of file +gulp.task('content', gulp.series('hugo', finalCommand)); diff --git a/package.json b/package.json index c01cb43..a71da5f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/games/app.js b/scripts/games/app.js index 99d6d84..dd75b06 100644 --- a/scripts/games/app.js +++ b/scripts/games/app.js @@ -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}`); } }