diff --git a/.github/workflows/bump-gitstream-core.yml b/.github/workflows/bump-gitstream-core.yml index d44592d9..481eb338 100644 --- a/.github/workflows/bump-gitstream-core.yml +++ b/.github/workflows/bump-gitstream-core.yml @@ -6,9 +6,9 @@ on: workflow_dispatch: inputs: version: - description: Version number (ex. "2.1.20") + description: Version number (ex. "2.1.133") required: true - default: 2.1.20 + default: 2.1.133 ticket: description: LINBEE-XXXX ticket number default: LINBEE-8514 @@ -16,6 +16,12 @@ on: description: description: Add a description for this version required: false + auto-deploy: + description: Add label "auto-deploy" to PR + required: false + type: boolean + default: true + jobs: publish_pr: name: Publish PR @@ -27,6 +33,12 @@ jobs: run: | echo "VERSION=${{ inputs.version }}" >> "$GITHUB_ENV" echo "BRANCH_NAME=${{ inputs.ticket }}-bump-gitstream-core-to-${{ inputs.version }}" >> "$GITHUB_ENV" + echo "LABEL_ARG=" >> "$GITHUB_ENV" + + - name: Set auto-deploy label + if: inputs.auto-deploy + run: | + echo "LABEL_ARG=--label auto-deploy" >> "$GITHUB_ENV" - name: Init npmrc run: | @@ -53,4 +65,4 @@ jobs: --title "Bump \`@linearb/gitstream-core\` to \`${{ env.VERSION }}\`" \ --body-file pr_description.txt \ --head ${{ env.BRANCH_NAME }} \ - --reviewer ${{ github.actor }} + --reviewer ${{ github.actor }} ${{ env.LABEL_ARG }} diff --git a/.github/workflows/create-tag-on-merge.yml b/.github/workflows/create-tag-on-merge.yml new file mode 100644 index 00000000..c18819e1 --- /dev/null +++ b/.github/workflows/create-tag-on-merge.yml @@ -0,0 +1,54 @@ +name: Create Tag on merge + +on: + workflow_dispatch: + push: + branches: + - develop + paths: + - src/** + - dist/** + - package*.json + +jobs: + create-tag: + runs-on: ubuntu-24.04 + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + + - name: Create and push new tag + run: npm run create-tag + + - name: Get latest commit + id: get-commit + run: echo "LAST_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Check for associated pull request and auto-deploy label + id: should-deploy + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const commit_sha = '${{ env.LAST_SHA }}'; + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ commit_sha, owner, repo }); + if (prs?.length > 0) { + const pull_number = prs[0].number; + const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number }); + return pr.labels.some(label => label.name.includes('auto-deploy')); + } + return false; + + - name: Create GitHub Release & Deploy + if: steps.should-deploy.outputs.result == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create $NEW_TAG --generate-notes + git checkout $NEW_TAG + npm run update-v2-tag diff --git a/package.json b/package.json index a8fe22eb..852532f8 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,9 @@ "lint": "eslint . -c ./.github/linters/.eslintrc.yml", "package": "ncc build --minify src/index.ts -o dist --license licenses.txt", "test": "jest", - "all": "npm run format:write && npm run lint && npm run test && npm run package" + "all": "npm run format:write && npm run lint && npm run test && npm run package", + "create-tag": "./scripts/tag-version.sh", + "update-v2-tag": "git tag v2 -f && git push origin v2 -f" }, "license": "Apache-2.0", "dependencies": { diff --git a/scripts/tag-version.sh b/scripts/tag-version.sh new file mode 100755 index 00000000..82ee95f4 --- /dev/null +++ b/scripts/tag-version.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +git fetch --tags + +# Get the latest tag +latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + +# Check if the latest tag starts with 'v' and remove it +if [[ $latest_tag == v* ]]; then + latest_tag=${latest_tag:1} +fi + +# Split the latest tag into an array +IFS='.' read -r -a version_parts <<< "$latest_tag" + +# Bump the patch version +new_tag="${version_parts[0]}.${version_parts[1]}.$((version_parts[2] + 1))" + +# Create and push the new tag +git tag $new_tag +git push origin $new_tag +echo "new_tag=$new_tag" + +echo "new_tag=$new_tag" >> $GITHUB_OUTPUT +echo "NEW_TAG=$new_tag" >> $GITHUB_ENV \ No newline at end of file