Skip to content

Commit

Permalink
prebuilt-tdlib update
Browse files Browse the repository at this point in the history
The publishing process of prebuilt-tdlib is heavily changed, everything
is now in the publish.js script (check-prebuilds.js and
write-tdlib-json.js are subsumed), which prepares the prebuilt-tdlib
package (updates its name and version, removes private) and publishes
it.

It is no longer necessary to specify the full padded npm version to run
the prebuilt-tdlib workflow. The input parameter is changed from
npm-version to npm-patch (accepts a single number).

The name of prebuilt-tdlib/package.json in this repository is now
prebuilt-tdlib-dev, which can allow to install prebuilt-tdlib as a dev
dependency here in the future.

The prebuilt-tdlib package is now published with the tdlib field in
package.json (contains "commit" and "version" properties), which should
enable to run convenient queries like `npm info prebuilt-tdlib
tdlib.commit`.
  • Loading branch information
eilvelia committed May 8, 2024
1 parent 75de4bc commit c0edcbc
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 66 deletions.
22 changes: 5 additions & 17 deletions .github/workflows/prebuilt-tdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
description: 'TDLib git ref (e.g. v1.8.0 or a commit hash)'
type: string
required: true
npm-version:
description: 'prebuilt-tdlib version to publish on npm (required to publish)'
npm-patch:
description: 'prebuilt-tdlib patch version, required to publish (e.g. 0, 1)'
type: string
required: false
npm-tag:
Expand Down Expand Up @@ -224,7 +224,6 @@ jobs:
publish:
name: 'Publish to npm'
needs: [test]
if: "${{ inputs.npm-version != '' }}"
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -252,20 +251,9 @@ jobs:
echo "TDLIB_COMMIT_HASH=$(git rev-parse ${{ inputs.tdlib }})" >> "$GITHUB_ENV"
__ver=`grep -Po "(?<=TDLib VERSION )\d+\.\d+\.\d+" ./CMakeLists.txt`
echo "TDLIB_VERSION=$__ver" >> "$GITHUB_ENV"
- run: node packages/prebuilt-tdlib/check-prebuilds.js
- run: node packages/prebuilt-tdlib/write-tdlib-json.js $TDLIB_COMMIT_HASH $TDLIB_VERSION
- run: cat packages/prebuilt-tdlib/prebuilds/tdlib.json
- name: Update version
run: npm version ${{ inputs.npm-version }} --no-git-tag-version -w prebuilt-tdlib
echo NPM_TAG=${{ inputs.npm-tag }} >> "$GITHUB_ENV"
- name: Publish
run: |
npm publish --provenance --access public --tag ${{ inputs.npm-tag }} -w prebuilt-tdlib
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Set the td- tag
run: |
npm dist-tag add \
prebuilt-tdlib@${{ inputs.npm-version }} td-$TDLIB_VERSION \
-w prebuilt-tdlib
run: node packages/prebuilt-tdlib/publish.js ${{ inputs.npm-patch }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: "${{ inputs.npm-patch != '' }}"
9 changes: 6 additions & 3 deletions packages/prebuilt-tdlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ not have a specific git-tagged release. Most `prebuilt-tdlib` releases are not
connected to a tag release in the TDLib repository. Usually, the prebuilt
packages are generated based on the "Update version to x.y.z." TDLib commits
([example][commit-example]). Otherwise, the commit hash is indicated in the list
below. Since `prebuilt-tdlib@td-1.8.19` (2023-09-26), the packages include a
`prebuilds/tdlib.json` file specifying the commit hash and version of TDLib.
below.

[commit-example]: https://github.com/tdlib/td/commit/b3b63bbdc14dc377d2de6b78e5844fec1564f95d

Expand Down Expand Up @@ -123,10 +122,14 @@ versions):

Changes to the building process of `prebuilt-tdlib` are noted below.

### 2024-04-30
### 2024-05-08

First published as `prebuil-tdlib@td-1.8.29`.

- Added a `tdlib: { commit: ..., version: ... }` field to `package.json`. This
allows to query information using `npm info prebuilt-tdlib tdlib.commit`, for
example.
- Added `commit` as an alias for `ref`. to `tdlib.json`.
- The packages are now published with `--provenance`.

### 2023-09-26
Expand Down
16 changes: 0 additions & 16 deletions packages/prebuilt-tdlib/check-prebuilds.js

This file was deleted.

12 changes: 7 additions & 5 deletions packages/prebuilt-tdlib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "prebuilt-tdlib",
"version": "0.0.1",
"description": "Prebuilt TDLib libraries",
"name": "prebuilt-tdlib-dev",
"version": "0.0.0",
"description": "Pre-built TDLib libraries",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
Expand All @@ -17,7 +17,8 @@
"keywords": [
"telegram",
"telegram-api",
"tdlib"
"tdlib",
"prebuilt"
],
"repository": {
"type": "git",
Expand All @@ -26,5 +27,6 @@
"bugs": {
"url": "https://github.com/Bannerets/tdl/issues"
},
"homepage": "https://github.com/Bannerets/tdl/tree/main/packages/prebuilt-tdlib#readme"
"homepage": "https://github.com/Bannerets/tdl/tree/main/packages/prebuilt-tdlib#readme",
"private": true
}
86 changes: 86 additions & 0 deletions packages/prebuilt-tdlib/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env/node
// @flow

const path = require('path')
const fs = require('fs')
const { execSync } = require('child_process')

const packageName = 'prebuilt-tdlib'

const tdlibCommit = process.env.TDLIB_COMMIT_HASH
let tdlibVersion = process.env.TDLIB_VERSION
const npmTag = process.env.NPM_TAG
const patchVersion = process.argv[2]

if (!tdlibCommit) throw new Error('Expected TDLIB_COMMIT_HASH')
if (!tdlibVersion) throw new Error('Expected TDLIB_VERSION')
if (!npmTag) throw new Error('Expected NPM_TAG')
if (!patchVersion) throw new Error('Expected the patch version')

if (Number.isNaN(Number(patchVersion)))
throw new Error(`Incorrect patch version: ${patchVersion}`)

if (tdlibCommit.length < 40) throw new Error('Too short TDLib commit')

tdlibVersion = tdlibVersion.replace(/^v/, '')

let [tdlibMajor, tdlibMinor, tdlibPatch] = tdlibVersion.split('.')

if (tdlibMajor == null || tdlibMinor == null || tdlibPatch == null)
throw new Error(`Incorrect TDLib version: ${tdlibVersion}`)

tdlibMinor = tdlibMinor.padStart(3, '0')
tdlibPatch = tdlibPatch.padStart(3, '0')

const npmVersion = `0.${tdlibMajor}${tdlibMinor}${tdlibPatch}.${patchVersion}`

console.log(`Preparing to publish ${npmVersion}`)

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

delete packageJson.private
packageJson.name = packageName
packageJson.version = npmVersion
packageJson.tdlib = {
commit: tdlibCommit,
version: tdlibVersion
}

const tdlibJson =
{ commit: tdlibCommit, version: tdlibVersion, ref: tdlibCommit }

fs.writeFileSync(
path.join(__dirname, 'prebuilds', 'tdlib.json'),
JSON.stringify(tdlibJson) + '\n'
)

fs.writeFileSync(
path.join(__dirname, 'package.json'),
JSON.stringify(packageJson, null, ' ') + '\n'
)

// Check

function checkExists (pathparts/*: string[] */) {
const p = path.join(__dirname, 'prebuilds', ...pathparts)
if (fs.existsSync(p)) return
throw new Error(`'${p}' does not exist`)
}

checkExists(['tdlib-linux-x64', 'libtdjson.so'])
checkExists(['tdlib-macos', 'libtdjson.dylib'])
checkExists(['tdlib-windows-x64', 'tdjson.dll'])

checkExists(['tdlib.json'])

// Publish

const publishCommand =
`npm publish --provenance --access public --tag ${npmTag} -w prebuilt-tdlib-dev`

const addTagCommand =
`npm dist-tag add ${packageName}@${npmVersion} td-${tdlibVersion} ` +
'-w prebuilt-tdlib-dev'

execSync(publishCommand, { stdio: 'inherit' })
execSync(addTagCommand, { stdio: 'inherit' })
17 changes: 0 additions & 17 deletions packages/prebuilt-tdlib/write-tdlib-json.js

This file was deleted.

10 changes: 2 additions & 8 deletions scripts/run-prebuilt-tdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@ version=$1
npm_patch="${2:-0}"

if [ -z "$version" ]; then
echo "Expected version"
echo "Not enough arguments: expected TDLib version"
exit 1
fi

td_major=$(echo $version | cut -d '.' -f 1)
td_minor=$(printf "%03d\n" $(echo $version | cut -d '.' -f 2))
td_patch=$(printf "%03d\n" $(echo $version | cut -d '.' -f 3))

npm_version="0.$td_major$td_minor$td_patch.$npm_patch"

commit=$(gh search commits "Update version to $version" -R tdlib/td --json sha --jq '.[0].sha')

if [ -z "$commit" ]; then
echo "Cannot find version $version"
exit 1
fi

command="gh workflow run prebuilt-tdlib.yml --ref develop -f tdlib=$commit -f npm-version=$npm_version"
command="gh workflow run prebuilt-tdlib.yml --ref develop -f tdlib=$commit -f npm-patch=$npm_patch"

echo "TDLib commit: https://github.com/tdlib/td/commit/$commit"
echo "Command: $command"
Expand Down

0 comments on commit c0edcbc

Please sign in to comment.