Skip to content

Commit

Permalink
ci: migrate to GitHub Actions (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored May 2, 2021
1 parent 0a54e3e commit 6e29667
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 41 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tester

on: [push, pull_request]

jobs:
tester:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
- name: Install Dependencies
run: npm install
- name: Lint
run: npm run eslint
- name: Test
run: npm run build
env:
CI: true
- name: Comment PR
uses: marocchino/sticky-pull-request-comment@v2
with:
path: public/validate_theme.txt
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Hexo Official Website
<!-- Markdown snippet -->
[![Build Status](https://travis-ci.org/hexojs/site.svg?branch=master)](https://travis-ci.org/hexojs/site)
[![Build Status](https://github.com/hexojs/site/workflows/Tester/badge.svg?branch=master)](https://github.com/hexojs/site/actions?query=workflow%3ATester)
[![Netlify Status](https://api.netlify.com/api/v1/badges/beeb7e86-4485-4381-8529-6b2a92df5dd7/deploy-status)](https://app.netlify.com/sites/hexo-site/deploys)

The website for Hexo.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"hexo-renderer-stylus": "^2.0.0",
"hexo-server": "^2.0.0",
"hexo-uglify": "^2.0.0",
"image-size": "^1.0.0",
"lunr": "2.3.9",
"sharp": "^0.28.1"
},
Expand All @@ -43,9 +42,10 @@
"*.{png,jpeg,jpg,gif,svg}": [
"imagemin-lint-staged",
"git add"
]
],
"*.js": "eslint --fix"
},
"engines": {
"node": ">=8.10.0"
"node": ">=12.9.0"
}
}
76 changes: 50 additions & 26 deletions scripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,83 @@
const { join } = require('path');

const { listDir } = require('hexo-fs');
const { log } = hexo;
const sizeOf = require('image-size');
const sharp = require('sharp');

async function validateThemeNames() {
function difference(setA, setB) {
const diff = new Set(setA);
for (const elem of setB) {
diff.delete(elem);
}
return diff;
}

async function validateTheme() {
const message = [];
let isValidationPassed = true;

const themeData = hexo.locals.get('data').themes;
const themeNames = [];
let name = '';
const themes = new Set();
const duplicate = new Set();
for (const theme of themeData) {
name = String(theme.name).toLocaleLowerCase();
if (themeNames.indexOf(name) !== -1) {
isValidationPassed = false;
break;
const name = theme.name.toLocaleLowerCase();
if (themes.has(name)) {
duplicate.add(name);
} else {
themeNames.push(name);
themes.add(name);
}
}

if (!isValidationPassed) {
throw new Error(`Theme name: [${name}] is duplicated.`);
if (duplicate.size > 0) {
message.push(`Theme name: ${Array.from(duplicate)} is duplicated.`);
isValidationPassed = false;
} else {
log.info('Theme name validation passed');
message.push('Theme name validation passed.');
}
}

async function validateThemeThumbnail() {
let isValidationPassed = true;
const screenshotsPath = join(hexo.source_dir, 'themes/screenshots');
const screenshots = await listDir(screenshotsPath);
let screenshots = await listDir(screenshotsPath);

screenshots.forEach(filename => {
for (const filename of screenshots) {
if (!filename.endsWith('.png')) {
log.fatal(`The theme thumbnail "${filename}" is not a png image.`);
message.push(`The theme thumbnail "${filename}" is not a png image.`);
isValidationPassed = false;
}

const screenshot = join(screenshotsPath, filename);

const { width, height } = sizeOf(screenshot);
const { width, height } = await sharp(screenshot).metadata();
if (width !== 800 || height !== 500) {
log.fatal(
message.push(
`The theme thumbnail "${filename}" is not sized in 800x500 (got ${width}x${height}).`
);
isValidationPassed = false;
}
});
}

screenshots = new Set(screenshots.map(name => name.replace('.png', '').toLocaleLowerCase()));

const diffThemesScreenshots = difference(themes, screenshots);
const diffScreenshotsThemes = difference(screenshots, themes);

if (diffThemesScreenshots.size > 0) {
message.push(`Theme screenshots not found: ${Array.from(diffThemesScreenshots)}.`);
isValidationPassed = false;
}
if (diffScreenshotsThemes.size > 0) {
message.push(`Theme screenshots not removed: ${Array.from(diffScreenshotsThemes)}.`);
isValidationPassed = false;
}

if (!isValidationPassed) {
throw new Error('Theme thumbnails validation failed');
message.push('Theme thumbnails validation failed.');
} else {
log.info('Theme thumbnails validation completed');
message.push('Theme thumbnails validation completed.');
}

return {
path: 'validate_theme.txt',
data: message.join('\n')
};
}

hexo.extend.filter.register('before_exit', validateThemeNames);
hexo.extend.filter.register('before_exit', validateThemeThumbnail);
if (process.env.CI) hexo.extend.generator.register('validate_theme', validateTheme);
Empty file modified source/themes/screenshots/AirCloud.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified source/themes/screenshots/flex-block.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e29667

Please sign in to comment.