diff --git a/.github/prepare_slim_package.sh b/.github/prepare_slim_package.sh new file mode 100644 index 0000000..a5102d9 --- /dev/null +++ b/.github/prepare_slim_package.sh @@ -0,0 +1,17 @@ +# Create a slim folder with the minium content we want, and remove unneeded files +mkdir slim && cp -r artifacts* package.json README.md deployments slim && cd slim +find deployments -mindepth 1 -depth -not -name "*_addresses.json*" -exec rm -r "{}" + +find artifacts -mindepth 1 -depth -not -regex "artifacts/contracts.*" -exec rm -r "{}" + +find artifacts-zk -mindepth 1 -depth -not -regex "artifacts-zk/contracts.*" -exec rm -r "{}" + +find artifacts -mindepth 1 -depth -regex "artifacts/.*dbg\.json" -exec rm -r "{}" + + +# Add "-slim" to the version in the npm package, keeping the tag "-dev" if it exists +jq '.version |= sub("^(?[0-9]+\\.[0-9]+\\.[0-9]+)"; "\(.core)-slim")' package.json > package.tmp.json && mv package.tmp.json package.json + +# Remove the "prepare" and "postinstall" scripts, they won't work for this slim version +jq 'del(.scripts.prepare)' package.json > package.tmp.json && mv package.tmp.json package.json +jq 'del(.scripts.postinstall)' package.json > package.tmp.json && mv package.tmp.json package.json + +# Empty devDependencies and dependencies +jq '.dependencies = {}' package.json > package.tmp.json && mv package.tmp.json package.json +jq '.devDependencies = {}' package.json > package.tmp.json && mv package.tmp.json package.json diff --git a/.github/publish_slim_package.sh b/.github/publish_slim_package.sh new file mode 100644 index 0000000..ccaa223 --- /dev/null +++ b/.github/publish_slim_package.sh @@ -0,0 +1,10 @@ +# Set npm authentication +echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + +cd slim + +# Extract to PRE_RELEASE_TAG the tag in the version field of the package json, or the empty string if it doesn't exist +PRE_RELEASE_TAG=$(jq -r '.version | if test("-") then capture("^[0-9]+\\.[0-9]+\\.[0-9]+-(?[a-zA-Z-]+)") | .tag else "" end' package.json) + +# Publish the package to a custom tag for slim versions +npm publish --provenance --access public --tag $PRE_RELEASE_TAG diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 0178a5d..34a2561 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -9,6 +9,8 @@ on: jobs: release: runs-on: ubuntu-latest + permissions: + id-token: write steps: - name: Checkout uses: actions/checkout@v3 @@ -36,3 +38,11 @@ jobs: GIT_COMMITTER_NAME: Venus Tools GIT_COMMITTER_EMAIL: tools@venus.io run: yarn semantic-release + + - name: Prepare slim package + run: bash .github/prepare_slim_package.sh + + - name: Publish slim package + run: bash .github/publish_slim_package.sh + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 52491d5..1713532 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@venusprotocol/token-bridge", "version": "2.7.1-dev.2", "description": "Contracts to bridge tokens using LayerZero technology and applying some rules on top of it", + "repository": "git@github.com:VenusProtocol/token-bridge.git", "files": [ "artifacts", "typechain",