ci: publish canary versions to private npm
This commit is contained in:
parent
8e07d7f552
commit
c95b5b70be
3 changed files with 64 additions and 0 deletions
8
.github/workflows/test.yaml
vendored
8
.github/workflows/test.yaml
vendored
|
@ -75,3 +75,11 @@ jobs:
|
|||
API_ID: ${{ secrets.TELEGRAM_API_ID }}
|
||||
API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
|
||||
run: cd e2e && ./cli.sh ci
|
||||
- name: Publish to canary NPM
|
||||
if: github.repository == 'mtcute/mtcute' # do not run on forks
|
||||
continue-on-error: true
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.CANARY_NPM_TOKEN }}
|
||||
E2E: 1
|
||||
REGISTRY: 'https://npm.tei.su'
|
||||
run: cd e2e && node publish-canary.js
|
||||
|
|
51
e2e/publish-canary.js
Normal file
51
e2e/publish-canary.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
// this scripts publishes our e2e-tested builds to canary npm
|
||||
// at this point, we should have all our packages installed in node_modules
|
||||
// so it should be safe to just cd into them and run `npm publish` on them
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
const { REGISTRY } = require('../scripts/publish.js')
|
||||
const { getCurrentCommit } = require('../scripts/git-utils.js')
|
||||
|
||||
// setup token
|
||||
const { NPM_TOKEN } = process.env
|
||||
|
||||
if (!NPM_TOKEN) {
|
||||
console.error('NPM_TOKEN is not set!')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
execSync(`npm config set //${REGISTRY.replace(/^https?:\/\//, '')}/:_authToken ${NPM_TOKEN}`, { stdio: 'inherit' })
|
||||
|
||||
const nodeModulesDir = path.join(__dirname, 'node_modules')
|
||||
const mtcuteDir = path.join(nodeModulesDir, '@mtcute')
|
||||
|
||||
const commit = getCurrentCommit().slice(0, 7)
|
||||
|
||||
for (const pkg of fs.readdirSync(mtcuteDir)) {
|
||||
const pkgJsonPath = path.join(mtcuteDir, pkg, 'package.json')
|
||||
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))
|
||||
const version = `${pkgJson.version}-git.${commit}`
|
||||
|
||||
fs.writeFileSync(
|
||||
pkgJsonPath,
|
||||
JSON.stringify(
|
||||
{
|
||||
...pkgJson,
|
||||
version,
|
||||
},
|
||||
null,
|
||||
4,
|
||||
),
|
||||
)
|
||||
|
||||
execSync(`npm publish --registry ${REGISTRY} -q --tag canary`, {
|
||||
cwd: path.join(mtcuteDir, pkg),
|
||||
stdio: 'inherit',
|
||||
})
|
||||
|
||||
// restore package.json just in case
|
||||
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4))
|
||||
}
|
|
@ -1,5 +1,9 @@
|
|||
const cp = require('child_process')
|
||||
|
||||
function getCurrentCommit() {
|
||||
return cp.execSync('git rev-parse HEAD', { encoding: 'utf8', stdio: 'pipe' }).trim()
|
||||
}
|
||||
|
||||
function getLatestTag() {
|
||||
try {
|
||||
const res = cp.execSync('git describe --abbrev=0 --tags', { encoding: 'utf8', stdio: 'pipe' }).trim()
|
||||
|
@ -64,4 +68,5 @@ module.exports = {
|
|||
findChangedFilesSince,
|
||||
getCommitsSince,
|
||||
parseConventionalCommit,
|
||||
getCurrentCommit,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue