ci: publish canary versions to private npm

This commit is contained in:
alina 🌸 2023-12-19 00:56:44 +03:00
parent 8e07d7f552
commit c95b5b70be
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
3 changed files with 64 additions and 0 deletions

View file

@ -75,3 +75,11 @@ jobs:
API_ID: ${{ secrets.TELEGRAM_API_ID }} API_ID: ${{ secrets.TELEGRAM_API_ID }}
API_HASH: ${{ secrets.TELEGRAM_API_HASH }} API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
run: cd e2e && ./cli.sh ci 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
View 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))
}

View file

@ -1,5 +1,9 @@
const cp = require('child_process') const cp = require('child_process')
function getCurrentCommit() {
return cp.execSync('git rev-parse HEAD', { encoding: 'utf8', stdio: 'pipe' }).trim()
}
function getLatestTag() { function getLatestTag() {
try { try {
const res = cp.execSync('git describe --abbrev=0 --tags', { encoding: 'utf8', stdio: 'pipe' }).trim() const res = cp.execSync('git describe --abbrev=0 --tags', { encoding: 'utf8', stdio: 'pipe' }).trim()
@ -64,4 +68,5 @@ module.exports = {
findChangedFilesSince, findChangedFilesSince,
getCommitsSince, getCommitsSince,
parseConventionalCommit, parseConventionalCommit,
getCurrentCommit,
} }