Skip to content

Commit

Permalink
build(actions): add nightly build action
Browse files Browse the repository at this point in the history
Add an action to run a nightly build at 22:00 UTC everyday and publish it to npm with the nightly tag.

This will allow users to use `npm install fomantic-ui@nightly` to use the latest features early.
  • Loading branch information
Sean committed Oct 23, 2019
1 parent 4b5cd6b commit fb9ec33
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: pre-install
run: sh preinstall.sh
run: sh ./scripts/preinstall.sh
- name: install dependencies
run: npm install --ignore-scripts
- name: pre fomantic install & gulp build
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Nightly
on:
schedule:
- cron: 00 23 * * *
jobs:
build:
name: Build nightly distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
ref: develop
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- name: pre-setup
run: sh ./scripts/preinstall.sh
- name: install dependencies
run: npm install --ignore-scripts
- name: update nightly version
run: node ./scripts/nightly-version.js
- name: fomantic install & build
run: npx gulp install
- name: publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm publish --tag nightly
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
CI: true
61 changes: 58 additions & 3 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
},
"devDependencies": {
"all-contributors-cli": "^6.7.0",
"auto-changelog": "^1.15.0"
"auto-changelog": "^1.15.0",
"node-fetch": "^2.6.0",
"semver": "^6.3.0"
},
"engines": {
"node": ">=10.15.3",
Expand Down
64 changes: 64 additions & 0 deletions scripts/nightly-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// node
const fs = require('fs')
const path = require('path')

// npm
const fetch = require('node-fetch')
const semver = require('semver')

// pkg
const pkg = require('../package.json')

const ghBase = 'https://api.github.com'
const repoUrlPath = 'fomantic/Fomantic-UI'
const npmBase = 'https://registry.npmjs.org'
const npmPackage = 'fomantic-ui'


const getGitHubVersion = async function () {
return fetch(`${ghBase}/repos/${repoUrlPath}/milestones`)
.then(r => r.json())
.then(milestones => milestones.filter(m => m.title.indexOf('x') === -1)[0].title)
}

const getCurrentNpmVersion = async function () {
return fetch(`${npmBase}/${npmPackage}`)
.then(r => r.json())
.then(p => p['dist-tags'].nightly)
}

const getNpmPreRelease = async function () {
return fetch(`${npmBase}/${npmPackage}`)
.then(r => r.json())
.then(p => p['dist-tags'].nightly)
.then(v => semver.prerelease(v))
.then(pr => pr === null ? ['beta', 0] : pr)
}

const getNightlyVersion = async function () {
const nextVersion = await getGitHubVersion()
const currentNightly = await getCurrentNpmVersion()

if (semver.minor(nextVersion) === semver.minor(currentNightly)) {
const preRelease = await getNpmPreRelease()

return semver.inc(
`${nextVersion}-${preRelease[0]}.${preRelease[1]}`,
'prerelease'
)
} else {
return `${nextVersion}-beta.1`
}
}

getNightlyVersion()
.then(nightlyVersion => {
pkg.version = nightlyVersion
})
.then(() => {
fs.writeFileSync(
path.resolve(__dirname, '../package.json'),
JSON.stringify(pkg, null, 2)
)
})
.then(() => console.log(`Done (${pkg.version})`))
File renamed without changes.

0 comments on commit fb9ec33

Please sign in to comment.