Skip to content

Commit

Permalink
chore(ci): use semantic-release for auto publish and release
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Dec 17, 2020
1 parent ba5cbdd commit ae7a11b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,25 @@
name: Release
on:
push:
branches:
- master
jobs:
release:
name: Release
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install dependencies
run: npm ci
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
7 changes: 4 additions & 3 deletions lib/utils.js
Expand Up @@ -141,15 +141,16 @@ exports.deprecate = (obj, prop, value, oldPath, newPath) => {


// Check for updates.
const { version } = require('../package.json');
const package = require('../package.json');
exports.lastUpdateCheck = 0;
exports.checkForUpdates = () => {
if (!process.env.YTDL_NO_UPDATE && Date.now() - exports.lastUpdateCheck >= 1000 * 60 * 60 * 12) {
if (!process.env.YTDL_NO_UPDATE && !package.version.startsWith('0.0.0-') &&
Date.now() - exports.lastUpdateCheck >= 1000 * 60 * 60 * 12) {
exports.lastUpdateCheck = Date.now();
return miniget('https://api.github.com/repos/fent/node-ytdl-core/releases/latest', {
headers: { 'User-Agent': 'ytdl-core' },
}).text().then(response => {
if (JSON.parse(response).tag_name !== `v${version}`) {
if (JSON.parse(response).tag_name !== `v${package.version}`) {
console.warn('\x1b[33mWARNING:\x1B[0m ytdl-core is out of date! Update with "npm install ytdl-core@latest".');
}
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "ytdl-core",
"description": "Youtube video downloader in pure javascript.",
"description": "YouTube video downloader in pure javascript.",
"keywords": [
"youtube",
"video",
"download"
],
"version": "4.1.6",
"version": "0.0.0-development",
"repository": {
"type": "git",
"url": "git://github.com/fent/node-ytdl-core.git"
Expand Down
7 changes: 5 additions & 2 deletions test/utils-test.js
Expand Up @@ -106,10 +106,11 @@ describe('utils.checkForUpdates', () => {

describe('Already on latest', () => {
it('Does not warn the console', async() => {
const { version } = require('../package.json');
const package = require('../package.json');
sinon.replace(package, 'version', 'v1.0.0');
const scope = nock('https://api.github.com')
.get('/repos/fent/node-ytdl-core/releases/latest')
.reply(200, { tag_name: `v${version}` });
.reply(200, { tag_name: `v${package.version}` });
const warnSpy = sinon.spy();
sinon.replace(console, 'warn', warnSpy);
sinon.replace(Date, 'now', sinon.stub().returns(Infinity));
Expand All @@ -121,6 +122,8 @@ describe('utils.checkForUpdates', () => {

describe('When there is a new update', () => {
it('Warns the console about the update', async() => {
const package = require('../package.json');
sinon.replace(package, 'version', 'v1.0.0');
const scope = nock('https://api.github.com')
.get('/repos/fent/node-ytdl-core/releases/latest')
.reply(200, { tag_name: 'vInfinity.0.0' });
Expand Down

0 comments on commit ae7a11b

Please sign in to comment.