Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
name: CI

on: pull_request
on:
push:
branches:
- main
pull_request:
branches:
- main
merge_group:
branches:
- main

permissions:
contents: read
Expand All @@ -19,4 +28,3 @@ jobs:

- name: Run tests
run: node ./test/runTests.js

169 changes: 169 additions & 0 deletions .github/workflows/bump-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: Bump tslib

on:
workflow_dispatch:
inputs:
bump:
description: Version component to bump
required: true
type: choice
options:
- patch
- minor
- major

run-name: Bump tslib (${{ inputs.bump }})

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
prepare:
if: github.repository == 'microsoft/tslib' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
source-sha: ${{ steps.source.outputs.sha }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: main
fetch-depth: 0
persist-credentials: false

- name: Record source commit
id: source
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 22.x

- name: Bump version
env:
BUMP: ${{ inputs.bump }}
run: |
set -euo pipefail
case "$BUMP" in
patch|minor|major) ;;
*) echo "Invalid version bump: $BUMP" >&2; exit 1 ;;
esac
npm version "$BUMP" --no-git-tag-version --ignore-scripts --package-lock=false
node <<'NODE'
const fs = require("fs");
const bower = JSON.parse(fs.readFileSync("bower.json", "utf8"));
bower.version = require("./package.json").version;
fs.writeFileSync("bower.json", JSON.stringify(bower, null, 2) + "\n");
NODE

npm install --prefix test --package-lock-only --ignore-scripts --no-audit --no-fund
packageVersion="$(jq -r '.version' package.json)"
lockVersion="$(jq -r '.packages[".."].version' test/package-lock.json)"
if [ "$packageVersion" != "$lockVersion" ]; then
echo "package.json version $packageVersion does not match test/package-lock.json version $lockVersion." >&2
exit 1
fi

- name: Run tests
run: node ./test/runTests.js

- name: Create version bump patch
run: git diff --binary -- package.json bower.json test/package-lock.json > tslib-bump.patch

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: tslib-bump
path: tslib-bump.patch
if-no-files-found: error

create-pr:
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
environment:
name: azure
deployment: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.prepare.outputs.source-sha }}
fetch-depth: 0
persist-credentials: false

- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: tslib-bump
path: ${{ runner.temp }}

- name: Apply version bump
run: |
set -euo pipefail
git apply --index "$RUNNER_TEMP/tslib-bump.patch"
mapfile -t changedFiles < <(git diff --cached --name-only)
expectedFiles=("bower.json" "package.json" "test/package-lock.json")
if [ "${changedFiles[*]}" != "${expectedFiles[*]}" ]; then
echo "Unexpected files in version bump: ${changedFiles[*]}" >&2
exit 1
fi

- uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}

- name: Create GitHub App token
id: app-token
uses: microsoft/create-github-app-token-via-key-vault@5ba0d436e9c3cac52feff4d1f2f66f9698ce4a2d # v1
with:
client-id: ${{ vars.TYPESCRIPT_AUTOMATION_GITHUB_APP_CLIENT_ID }}
key-id: ${{ vars.TYPESCRIPT_AUTOMATION_GITHUB_APP_KEY_ID }}
owner: microsoft
repositories: tslib
permission-contents: write
permission-pull-requests: write

- name: Commit, push, and open pull request
env:
SOURCE_SHA: ${{ needs.prepare.outputs.source-sha }}
GITHUB_APP_TOKEN: ${{ steps.app-token.outputs.token }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail
version="$(jq -r '.version' package.json)"
branch="tslib-release/v$version"
git switch -c "$branch"
git config user.email "290192711+typescript-automation[bot]@users.noreply.github.com"
git config user.name "typescript-automation[bot]"
git config core.hooksPath /dev/null
git commit -m "Bump tslib to $version"

basic_auth="$(node -e 'process.stdout.write(Buffer.from("x-access-token:" + process.env.GITHUB_APP_TOKEN).toString("base64"))')"
echo "::add-mask::$basic_auth"
git config --local http.https://github.com/.extraheader "AUTHORIZATION: basic ${basic_auth}"

if git ls-remote --exit-code --heads origin "$branch" >/dev/null; then
git fetch origin "refs/heads/$branch:refs/remotes/origin/$branch"
existingCommit="$(git rev-parse "origin/$branch")"
existingParent="$(git rev-parse "origin/$branch^")"
if [ "$existingParent" != "$SOURCE_SHA" ] || ! git diff --quiet HEAD "$existingCommit"; then
echo "Existing branch $branch does not match this release bump." >&2
exit 1
fi
else
git push --set-upstream origin "$branch"
fi

existingPr="$(gh pr list --repo microsoft/tslib --base main --head "$branch" --state open --json url --jq '.[0].url // empty')"
if [ -n "$existingPr" ]; then
echo "Pull request already exists: $existingPr"
else
gh pr create --repo microsoft/tslib --base main --head "$branch" \
--title "Bump tslib to $version" \
--body "Prepares tslib $version for release."
fi
33 changes: 0 additions & 33 deletions .github/workflows/publish.yaml

This file was deleted.

106 changes: 106 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Tag tslib release

on:
push:
branches: [main]
paths:
- package.json

concurrency:
group: tag-tslib-${{ github.sha }}
cancel-in-progress: false

permissions:
contents: read
id-token: write

defaults:
run:
shell: bash

jobs:
tag:
if: github.repository == 'microsoft/tslib'
runs-on: ubuntu-latest
environment:
name: azure
deployment: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 2
persist-credentials: false

- name: Check for version bump
id: version
run: |
set -euo pipefail
previousVersion="$(git show HEAD^:package.json | jq -r '.version')"
version="$(jq -r '.version' package.json)"
if [ "$previousVersion" = "$version" ]; then
echo "package.json changed without changing its version."
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! [[ "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "Invalid release version: $version" >&2
exit 1
fi
bowerVersion="$(jq -r '.version' bower.json)"
if [ "$version" != "$bowerVersion" ]; then
echo "package.json version $version does not match bower.json version $bowerVersion." >&2
exit 1
fi
lockVersion="$(jq -r '.packages[".."].version' test/package-lock.json)"
if [ "$version" != "$lockVersion" ]; then
echo "package.json version $version does not match test/package-lock.json version $lockVersion." >&2
exit 1
fi
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"

- uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0
if: steps.version.outputs.changed == 'true'
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}

- name: Create GitHub App token
if: steps.version.outputs.changed == 'true'
id: app-token
uses: microsoft/create-github-app-token-via-key-vault@5ba0d436e9c3cac52feff4d1f2f66f9698ce4a2d # v1
with:
client-id: ${{ vars.TYPESCRIPT_AUTOMATION_GITHUB_APP_CLIENT_ID }}
key-id: ${{ vars.TYPESCRIPT_AUTOMATION_GITHUB_APP_KEY_ID }}
owner: microsoft
repositories: tslib
permission-contents: write

- name: Create release tag
if: steps.version.outputs.changed == 'true'
env:
PACKAGE_VERSION: ${{ steps.version.outputs.version }}
GITHUB_APP_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail
tag="v$PACKAGE_VERSION"
git config user.email "290192711+typescript-automation[bot]@users.noreply.github.com"
git config user.name "typescript-automation[bot]"
git config core.hooksPath /dev/null
basic_auth="$(node -e 'process.stdout.write(Buffer.from("x-access-token:" + process.env.GITHUB_APP_TOKEN).toString("base64"))')"
echo "::add-mask::$basic_auth"
git config --local http.https://github.com/.extraheader "AUTHORIZATION: basic ${basic_auth}"

if git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null; then
git fetch origin "refs/tags/$tag:refs/tags/$tag"
existingCommit="$(git rev-list -n 1 "$tag")"
if [ "$existingCommit" != "$(git rev-parse HEAD)" ]; then
echo "Tag $tag already exists at $existingCommit." >&2
exit 1
fi
echo "Tag $tag already exists at the release commit."
exit 0
fi
git tag --annotate "$tag" --message "tslib $PACKAGE_VERSION"
git push origin "refs/tags/$tag"
13 changes: 7 additions & 6 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gitattributes
.github
bower.json
docs
test
.npmrc
.gitattributes
.github
build
bower.json
docs
test
.npmrc
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,9 @@ For JSPM users:

## Deployment

- Choose your new version number
- Set it in `package.json` and `bower.json`
- Create a tag: `git tag [version]`
- Push the tag: `git push --tags`
- Create a [release in GitHub](https://github.com/microsoft/tslib/releases)
- Run the [publish to npm](https://github.com/microsoft/tslib/actions?query=workflow%3A%22Publish+to+NPM%22) workflow

Done.
- Run the **Bump tslib** GitHub workflow and choose patch, minor, or major
- Review and squash-merge the generated version-bump PR
- The release runs automatically: tag, build, publish to npm, and create a GitHub release with generated notes

# Contribute

Expand Down
Loading
Loading