diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de204c210..f669693d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,3 +146,13 @@ jobs: name: ungit-win32-x64 path: dist/ungit-win32-x64.zip retention-days: 7 + + - name: npm publish + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '12' && github.repository == 'FredrikNoren/ungit' && github.ref == 'refs/heads/master' + uses: actions/github-script@v5 + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + with: + script: | + const script = require('./scripts/npmpublish.js') + await script({github, context, core}) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8659a6c9e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,76 +0,0 @@ -os: - - linux - - osx -# - windows -language: node_js -node_js: - - node - - '16' - - '14' - - '12' -branches: - only: - - master - - /^v\d+\.\d+\.\d+$/ -env: - jobs: - - GIT_VERSION=edge - - GIT_VERSION=default -jobs: - exclude: - - node_js: '16' - env: GIT_VERSION=edge - - node_js: '14' - env: GIT_VERSION=edge - - node_js: '12' - env: GIT_VERSION=edge - - os: windows - env: GIT_VERSION=edge -addons: - apt: - packages: - - wine -# required for electron-packager -# homebrew: -# update: true -# casks: -# - xquartz -# - wine-stable -before_install: - # linux - - if [[ $TRAVIS_OS_NAME = "linux" ]]; then wine --version; fi - - if [[ $TRAVIS_OS_NAME = "linux" && $GIT_VERSION = "edge" ]]; then sudo add-apt-repository ppa:git-core/ppa -y && sudo apt-get update -q && sudo apt-get install -y git; fi - # osx -# - if [[ $TRAVIS_OS_NAME = "osx" ]]; then export WINEDLLOVERRIDES='mscoree,mshtml='; fi -# - if [[ $TRAVIS_OS_NAME = "osx" ]]; then wine64 --version; fi - - if [[ $TRAVIS_OS_NAME = "osx" && $GIT_VERSION = "edge" ]]; then brew reinstall git; fi - # windows - # required for git clone ("git-receive-pack") and submodule ("git-submodule") tests - - if [[ $TRAVIS_OS_NAME = "windows" ]]; then export "PATH=$PATH:/c/Program Files/Git/mingw64/libexec/git-core/"; fi - # currently fails with Exit code was '1' - - if [[ $TRAVIS_OS_NAME = "windows" && $GIT_VERSION = "edge" ]]; then choco upgrade git; fi -install: - - npm ci -before_script: - - git config --global user.email "test@testy.com" - - git config --global user.name "Test testy" - - git --version - - npm run lint - - npm run build -after_success: - - npm run travisnpmpublish -before_deploy: - - npm run electronpackage -- --all - - npm run electronzip -deploy: - provider: releases - token: ${GITHUB_TOKEN} - name: ${TRAVIS_TAG} - file_glob: true - file: dist/*.zip - overwrite: true - edge: true - release_notes: "[Changelog](https://github.com/FredrikNoren/ungit/blob/master/CHANGELOG.md#${TRAVIS_TAG//[v\\.]})" - on: - tags: true - condition: $TRAVIS_OS_NAME = "linux" && $TRAVIS_NODE_VERSION = "12" diff --git a/package.json b/package.json index 64a877762..84b6b55af 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "watch": "nodemon -C --exec \"npm run build\" -e js,less -w public/source -w public/less -w components/ -i \"*.bundle.js\"", "bumpdependencies": "ncu --upgrade --reject bootstrap", "electronpackage": "node ./scripts/electronpackage.js", - "electronzip": "node ./scripts/electronzip.js", - "travisnpmpublish": "node ./scripts/travisnpmpublish.js" + "electronzip": "node ./scripts/electronzip.js" }, "repository": { "type": "git", diff --git a/scripts/npmpublish.js b/scripts/npmpublish.js new file mode 100644 index 000000000..798f88849 --- /dev/null +++ b/scripts/npmpublish.js @@ -0,0 +1,48 @@ +const child_process = require('child_process'); +const fs = require('fs').promises; +const path = require('path'); + +module.exports = async ({ github, context, core }) => { + core.info('Preparing npm publish'); + const hash = context.sha.substring(0, 8); + const packageJson = JSON.parse(await fs.readFile('package.json')); + const version = packageJson.version; + const tag = `v${version}`; + packageJson.version += `+${hash}`; + await fs.writeFile('package.json', `${JSON.stringify(packageJson, null, 2)}\n`); + await fs.writeFile('.npmrc', '//registry.npmjs.org/:_authToken=' + process.env.NPM_TOKEN); + core.info(`Publish ${packageJson.version} to npm`); + try { + await new Promise((resolve, reject) => { + child_process.exec('npm publish', async (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + core.info(`Creating release ${tag}`); + const release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + name: tag, + tag_name: tag, + body: `[Changelog](https://github.com/FredrikNoren/ungit/blob/master/CHANGELOG.md#${version.replace(/\./g, '')})` + }); + const filePaths = await fs.readdir('dist'); + for (let i = 0; i < filePaths.length; i++) { + const filePath = path.join('dist', filePaths[i]); + core.info(`Uploading release asset ${filePath}`); + await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.data.id, + name: path.basename(filePath).replace('ungit', `ungit-${version}`), + data: await fs.readFile(filePath) + }); + } + } catch (e) { + core.info(`npm publish failed: ${e}`); + } +} diff --git a/scripts/travisnpmpublish.js b/scripts/travisnpmpublish.js deleted file mode 100644 index d7bb66108..000000000 --- a/scripts/travisnpmpublish.js +++ /dev/null @@ -1,32 +0,0 @@ -const child_process = require('child_process'); -const fs = require('fs'); - -if ( - process.env.TRAVIS_BRANCH != 'master' || - (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST != 'false') -) { - console.log('Skipping travis npm publish'); -} else { - console.log('Preparing travis npm publish'); - child_process.exec('git rev-parse --short HEAD', (err, stdout, stderr) => { - const hash = stdout.trim(); - const packageJson = JSON.parse(fs.readFileSync('package.json')); - const version = packageJson.version; - packageJson.version += `+${hash}`; - fs.writeFileSync('package.json', `${JSON.stringify(packageJson, null, 2)}\n`); - fs.writeFileSync('.npmrc', '//registry.npmjs.org/:_authToken=' + process.env.NPM_TOKEN); - console.log(`Publish ${packageJson.version} to npm`); - child_process.exec('npm publish', (err) => { - if (err) throw err; - else { - console.log(`Create and push tag v${version}`); - child_process.exec( - `git tag v${version} && git push -q https://${process.env.GITHUB_TOKEN}@github.com/FredrikNoren/ungit.git v${version}`, - (err) => { - if (err) throw err; - } - ); - } - }); - }); -}