From 7dfb64ad78a61d774d94adbdeaf3f5af3342bc44 Mon Sep 17 00:00:00 2001 From: Stefan Niclas Heun Date: Fri, 7 Feb 2025 15:17:28 +0100 Subject: [PATCH] changing workflow --- .github/workflows/publish-state-lib.yml | 58 ++++++++++++++++++++----- prompt-shared-state/README.md | 2 + 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-state-lib.yml b/.github/workflows/publish-state-lib.yml index 7b4b176..0800f6a 100644 --- a/.github/workflows/publish-state-lib.yml +++ b/.github/workflows/publish-state-lib.yml @@ -4,12 +4,12 @@ on: push: branches: - main - # This restricts the workflow to run only if files in `prompt-shared-state/` changed. paths: - 'prompt-shared-state/**' permissions: - contents: write # Allows committing the version bump back to the repo + contents: write # Required for creating branches/PRs + pull-requests: write # Required for opening pull requests env: NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} @@ -17,6 +17,7 @@ env: jobs: publish: runs-on: ubuntu-latest + steps: - name: Check out repository uses: actions/checkout@v4 @@ -24,7 +25,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v4 with: - node-version: '23.x' + node-version: '16.x' registry-url: 'https://registry.npmjs.org' - name: Enable Corepack @@ -71,31 +72,66 @@ jobs: ;; esac - - name: Commit version bump + - name: Commit version bump and push to new branch + id: commit_bump run: | # Configure git git config user.name "github-actions" git config user.email "github-actions@github.com" - # Stage and commit changes if package.json or yarn.lock changed in subfolder - git add prompt-shared-state/package.json prompt-shared-state/yarn.lock || true + # Stage and commit changes if package.json or yarn.lock changed + git add prompt-shared-state/package.json prompt-shared-state/yarn.lock if ! git diff --cached --exit-code; then - # Pull out the newly bumped version from package.json in subfolder + # Pull out the newly bumped version NEW_VERSION=$(node -p "require('./prompt-shared-state/package.json').version") - git commit -m "chore: bump prompt-shared-state version to $NEW_VERSION [skip ci]" - git push origin HEAD:main + COMMIT_MSG="chore: bump prompt-shared-state version to $NEW_VERSION [skip ci]" + + # Commit + git commit -m "$COMMIT_MSG" + + # Create and push version-bump branch + BRANCH_NAME="chore/bump-prompt-shared-state-$NEW_VERSION" + git checkout -b "$BRANCH_NAME" + git push origin "$BRANCH_NAME" + + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT else echo "No version bump commit required." fi + - name: Create pull request + if: ${{ steps.commit_bump.outputs.branch_name != '' }} + uses: actions/github-script@v6 + + with: + script: | + const core = require('@actions/core'); + const github = require('@actions/github'); + + const branchName = ${{ steps.commit_bump.outputs.branch_name }}; + const newVersion = ${{ steps.commit_bump.outputs.new_version }}; + + const { data: pullRequest } = await github.pulls.create({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + title: `chore: bump prompt-shared-state version to ${newVersion}`, + head: branchName, + base: 'main', + body: 'This pull request was automatically opened by the version bump workflow.', + draft: false + }); + + core.setOutput('pull_request_number', pullRequest.number); + - name: Build the package - env: - NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + if: ${{ steps.commit_bump.outputs.branch_name != '' }} run: | cd prompt-shared-state yarn build - name: Publish to npm + if: ${{ steps.commit_bump.outputs.branch_name != '' }} env: NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} run: | diff --git a/prompt-shared-state/README.md b/prompt-shared-state/README.md index e6a61e3..b4483c3 100644 --- a/prompt-shared-state/README.md +++ b/prompt-shared-state/README.md @@ -101,3 +101,5 @@ Include **one** of the following keywords in your commit message to indicate how - Increments the patch version by default (e.g. `1.2.3` → `1.2.4`). If you do not include `major` or `minor` in your commit message, the workflow will assume a **patch** update. + +When the publishing worked, then a PR with a new version number has been opened. This shall be merged immediately. \ No newline at end of file