diff --git a/.github/workflows/bump-release.yml b/.github/workflows/bump-release.yml deleted file mode 100644 index 570eb1f..0000000 --- a/.github/workflows/bump-release.yml +++ /dev/null @@ -1,161 +0,0 @@ -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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - 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@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.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 - - - name: Run tests - run: node ./test/runTests.js - - - name: Create version bump patch - run: git diff --binary -- package.json bower.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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - 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") - 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 diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml deleted file mode 100644 index acae780..0000000 --- a/.github/workflows/tag-release.yml +++ /dev/null @@ -1,101 +0,0 @@ -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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - 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 - 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" diff --git a/README.md b/README.md index cf7d641..4c8ad53 100644 --- a/README.md +++ b/README.md @@ -138,9 +138,8 @@ For JSPM users: ## Deployment -- 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 +- Send a PR that changes the `version` field in `package.json` +- Once it is merged, the release pipeline (`build/azure-pipelines/release.yml`) builds, publishes to npm, tags the release, and creates a GitHub release with generated notes # Contribute diff --git a/bower.json b/bower.json index 858e67a..d3cc36e 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,6 @@ "Microsoft Corp." ], "homepage": "http://typescriptlang.org/", - "version": "2.9.1", "license": "0BSD", "description": "Runtime library for TypeScript helper functions", "keywords": [ diff --git a/build/azure-pipelines/release.yml b/build/azure-pipelines/release.yml index a9ca7a6..116c35e 100644 --- a/build/azure-pipelines/release.yml +++ b/build/azure-pipelines/release.yml @@ -2,11 +2,11 @@ name: $(date:yyyyMMdd).$(rev:r) trigger: branches: - exclude: - - "*" - tags: include: - - v* + - main + paths: + include: + - package.json pr: none variables: @@ -65,7 +65,7 @@ extends: displayName: "Publish npm package artifact" steps: - checkout: self - fetchDepth: 1 + fetchDepth: 2 - task: UseNode@1 inputs: @@ -80,26 +80,20 @@ extends: package_spec="$package_name@$package_version" staging="$(Build.ArtifactStagingDirectory)/$(NpmArtifactName)" - if [[ "$BUILD_SOURCEBRANCH" != refs/tags/* ]]; then - echo "Not building a tag; not staging a package artifact." + previous_version="$(git show HEAD~1:package.json | node -p 'JSON.parse(require("fs").readFileSync(0, "utf8")).version')" + if [ "$BUILD_SOURCEBRANCH" != refs/heads/main ] || [ "$previous_version" = "$package_version" ]; then + echo "No version change on main; not staging a package artifact." echo "##vso[task.setvariable variable=ShouldPack]false" echo "##vso[task.setvariable variable=ShouldPublish;isOutput=true]false" exit 0 fi - tag="${BUILD_SOURCEBRANCH#refs/tags/}" - if ! [[ "$package_version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || [ "$tag" != "v$package_version" ]; then - echo "Tag $tag does not match a stable package.json version v$package_version." >&2 + if ! [[ "$package_version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then + echo "package.json version $package_version is not a stable version." >&2 exit 1 fi - bower_version="$(node -p "require('./bower.json').version")" - if [ "$package_version" != "$bower_version" ]; then - echo "package.json version $package_version does not match bower.json version $bower_version." >&2 - exit 1 - fi - - echo "Tag $tag matches package.json version $package_version; staging $package_spec." + echo "Version changed from $previous_version to $package_version; staging $package_spec." mkdir -p "$staging" npm pack --pack-destination "$staging" @@ -118,7 +112,7 @@ extends: echo "##vso[task.setvariable variable=PackageVersion;isOutput=true]$package_version" echo "##vso[build.updatebuildnumber]$(Build.BuildNumber)-release.$package_version" name: publishCheck - displayName: "Check tag and pack npm package" + displayName: "Check version and pack npm package" - stage: Publish displayName: Publish to npmjs @@ -148,7 +142,7 @@ extends: approvers: "$(ReleaseApprovers)" - stage: Finalize - displayName: Create GitHub release + displayName: Create release tag and GitHub release dependsOn: - Build - Publish @@ -157,7 +151,7 @@ extends: PackageVersion: $[stageDependencies.Build.Build.outputs['publishCheck.PackageVersion']] jobs: - job: CreateGitHubRelease - displayName: Create tslib GitHub release + displayName: Create tslib release tag and GitHub release templateContext: type: releaseJob isProduction: true @@ -206,14 +200,23 @@ extends: async function finalize() { const ref = await request(`git/ref/tags/${tag}`); if (!ref) { - throw new Error(`Expected release tag ${tag} does not exist.`); - } - let object = ref.object; - while (object.type === "tag") { - object = (await request(`git/tags/${object.sha}`)).object; + const tagObject = await request("git/tags", "POST", { + tag, + message: `tslib ${version}`, + object: commit, + type: "commit", + }); + await request("git/refs", "POST", { ref: `refs/tags/${tag}`, sha: tagObject.sha }); + console.log(`Created tag ${tag} at ${commit}.`); } - if (object.type !== "commit" || object.sha !== commit) { - throw new Error(`Tag ${tag} does not point to the published commit ${commit}.`); + else { + let object = ref.object; + while (object.type === "tag") { + object = (await request(`git/tags/${object.sha}`)).object; + } + if (object.type !== "commit" || object.sha !== commit) { + throw new Error(`Tag ${tag} does not point to the published commit ${commit}.`); + } } const release = await request(`releases/tags/${tag}`); if (release) { @@ -235,7 +238,7 @@ extends: process.exitCode = 1; }); NODE - displayName: Create tslib GitHub release + displayName: Create tslib release tag and GitHub release env: GH_TOKEN: $(GH_TOKEN) PACKAGE_VERSION: $(PackageVersion)