From 187e7eb0e847c509f62c902fe3a7203fffb7275a Mon Sep 17 00:00:00 2001 From: Akshat Nema <76521428+akshatnema@users.noreply.github.com> Date: Fri, 13 Dec 2024 21:46:14 +0530 Subject: [PATCH] fix: changeset configuration and github action (#1590) * updated commit for changeset config * updated changeset github workflow * updated version command in changeset action --- .github/workflows/if-nodejs-release.yml | 134 ------------------ .github/workflows/if-nodejs-version-bump.yml | 69 --------- .github/workflows/release-with-changesets.yml | 44 +----- .releaserc | 24 ---- github-action/lib/bump-action-version.js | 30 ++-- package.json | 4 +- 6 files changed, 18 insertions(+), 287 deletions(-) delete mode 100644 .github/workflows/if-nodejs-release.yml delete mode 100644 .github/workflows/if-nodejs-version-bump.yml delete mode 100644 .releaserc diff --git a/.github/workflows/if-nodejs-release.yml b/.github/workflows/if-nodejs-release.yml deleted file mode 100644 index 72d01de477a..00000000000 --- a/.github/workflows/if-nodejs-release.yml +++ /dev/null @@ -1,134 +0,0 @@ -# This action is centrally managed in https://github.com/asyncapi/.github/ -# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo - -# It does magic only if there is package.json file in the root of the project -name: Release - if Node project - -on: - push: - branches: - - master - # below lines are not enough to have release supported for these branches - # make sure configuration of `semantic-release` package mentions these branches - - next-spec - - next-major - - next-major-spec - - beta - - alpha - - next - -jobs: - - test-nodejs: - # We just check the message of first commit as there is always just one commit because we squash into one before merging - # "commits" contains array of objects where one of the properties is commit "message" - # Release workflow will be skipped if release conventional commits are not used - if: | - startsWith( github.repository, 'asyncapi/' ) && - (startsWith( github.event.commits[0].message , 'fix:' ) || - startsWith( github.event.commits[0].message, 'fix!:' ) || - startsWith( github.event.commits[0].message, 'feat:' ) || - startsWith( github.event.commits[0].message, 'feat!:' )) - name: Test NodeJS release on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - # Using macos-13 instead of latest (macos-14) due to an issue with Puppeteer and such runner. - # See: https://github.com/puppeteer/puppeteer/issues/12327 and https://github.com/asyncapi/parser-js/issues/1001 - os: [ubuntu-latest, macos-13, windows-latest] - steps: - - name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows - run: | - git config --global core.autocrlf false - git config --global core.eol lf - shell: bash - - name: Checkout repository - uses: actions/checkout@v4 - - name: Check if Node.js project and has package.json - id: packagejson - run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT - shell: bash - - if: steps.packagejson.outputs.exists == 'true' - name: Check package-lock version - uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master - id: lockversion - - if: steps.packagejson.outputs.exists == 'true' - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "${{ steps.lockversion.outputs.version }}" - - if: steps.lockversion.outputs.version == '18' && matrix.os == 'windows-latest' - name: Install npm cli 8 - shell: bash - #npm cli 10 is buggy because of some cache issues - run: npm install -g npm@8.19.4 - - if: steps.packagejson.outputs.exists == 'true' - name: Install dependencies - shell: bash - run: npm ci - - if: steps.packagejson.outputs.exists == 'true' - name: Run test - run: npm test --if-present - - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel - name: Report workflow run status to Slack - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,action,workflow - text: 'Release workflow failed in testing job' - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} - - release: - needs: [test-nodejs] - name: Publish to any of NPM, Github, or Docker Hub - runs-on: ubuntu-latest - steps: - - name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - name: Checkout repository - uses: actions/checkout@v4 - - name: Check if Node.js project and has package.json - id: packagejson - run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT - shell: bash - - if: steps.packagejson.outputs.exists == 'true' - name: Check package-lock version - uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master - id: lockversion - - if: steps.packagejson.outputs.exists == 'true' - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "${{ steps.lockversion.outputs.version }}" - - if: steps.packagejson.outputs.exists == 'true' - name: Install dependencies - shell: bash - run: npm ci - - if: steps.packagejson.outputs.exists == 'true' - name: Add plugin for conventional commits for semantic-release - run: npm install --save-dev conventional-changelog-conventionalcommits@5.0.0 - - if: steps.packagejson.outputs.exists == 'true' - name: Publish to any of NPM, Github, and Docker Hub - id: release - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - GIT_AUTHOR_NAME: asyncapi-bot - GIT_AUTHOR_EMAIL: info@asyncapi.io - GIT_COMMITTER_NAME: asyncapi-bot - GIT_COMMITTER_EMAIL: info@asyncapi.io - run: npx semantic-release@19.0.4 - - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel - name: Report workflow run status to Slack - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,action,workflow - text: 'Release workflow failed in release job' - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} diff --git a/.github/workflows/if-nodejs-version-bump.yml b/.github/workflows/if-nodejs-version-bump.yml deleted file mode 100644 index 36847d803a0..00000000000 --- a/.github/workflows/if-nodejs-version-bump.yml +++ /dev/null @@ -1,69 +0,0 @@ -# This action is centrally managed in https://github.com/asyncapi/.github/ -# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo - -# It does magic only if there is package.json file in the root of the project -name: Version bump - if Node.js project - -on: - release: - types: - - published - -jobs: - version_bump: - name: Generate assets and bump NodeJS - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - # target branch of release. More info https://docs.github.com/en/rest/reference/repos#releases - # in case release is created from release branch then we need to checkout from given branch - # if @semantic-release/github is used to publish, the minimum version is 7.2.0 for proper working - ref: ${{ github.event.release.target_commitish }} - - name: Check if Node.js project and has package.json - id: packagejson - run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT - - if: steps.packagejson.outputs.exists == 'true' - name: Check package-lock version - uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master - id: lockversion - - if: steps.packagejson.outputs.exists == 'true' - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "${{ steps.lockversion.outputs.version }}" - cache: 'npm' - cache-dependency-path: '**/package-lock.json' - - if: steps.packagejson.outputs.exists == 'true' - name: Install dependencies - run: npm ci - - if: steps.packagejson.outputs.exists == 'true' - name: Assets generation - run: npm run generate:assets --if-present - - if: steps.packagejson.outputs.exists == 'true' - name: Bump version in package.json - # There is no need to substract "v" from the tag as version script handles it - # When adding "bump:version" script in package.json, make sure no tags are added by default (--no-git-tag-version) as they are already added by release workflow - # When adding "bump:version" script in package.json, make sure --allow-same-version is set in case someone forgot and updated package.json manually and we want to avoide this action to fail and raise confusion - run: VERSION=${{github.event.release.tag_name}} npm run bump:version - - if: steps.packagejson.outputs.exists == 'true' - name: Create Pull Request with updated asset files including package.json - uses: peter-evans/create-pull-request@38e0b6e68b4c852a5500a94740f0e535e0d7ba54 # use 4.2.4 https://github.com/peter-evans/create-pull-request/releases/tag/v4.2.4 - with: - token: ${{ secrets.GH_TOKEN }} - commit-message: 'chore(release): ${{github.event.release.tag_name}}' - committer: asyncapi-bot - author: asyncapi-bot - title: 'chore(release): ${{github.event.release.tag_name}}' - body: 'Version bump in package.json for release [${{github.event.release.tag_name}}](${{github.event.release.html_url}})' - branch: version-bump/${{github.event.release.tag_name}} - - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel - name: Report workflow run status to Slack - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,action,workflow - text: 'Unable to bump the version in package.json after the release' - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} \ No newline at end of file diff --git a/.github/workflows/release-with-changesets.yml b/.github/workflows/release-with-changesets.yml index 45498ebd033..a05e09c79da 100644 --- a/.github/workflows/release-with-changesets.yml +++ b/.github/workflows/release-with-changesets.yml @@ -108,47 +108,6 @@ jobs: shell: bash # This step can be removed once the issue is fixed in the changeset package. run: npm install @changesets/changelog-git@0.2.0 - - if: steps.packagejson.outputs.exists == 'true' - name: Get version update from the changeset - uses: changesets/action@v1 - with: - version: npx -p @changesets/cli@2.27.7 changeset version - commit: "chore(release): release and bump versions of packages" - title: "chore(release): release and bump versions of packages" - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - GIT_AUTHOR_NAME: asyncapi-bot - GIT_AUTHOR_EMAIL: info@asyncapi.io - GIT_COMMITTER_NAME: asyncapi-bot - GIT_COMMITTER_EMAIL: info@asyncapi.io - - - if: steps.packagejson.outputs.exists == 'true' - name: Get version from package.json - id: get-version - run: echo ::set-output name=version::$(node -p "require('./package.json').version") - - - if: steps.packagejson.outputs.exists == 'true' - name: Update version inside action.yml - uses: actions/github-script@v6 - with: - script: | - const fs = require('fs'); - const path = require('path'); - - const templatePath = path.resolve('./', 'action-template.yml'); - const outputPath = path.resolve('./', 'action.yml'); - - const templateContent = fs.readFileSync(templatePath, 'utf8'); - const updatedContent = templateContent.replace(/\${ version }/g, '${{ steps.get-version.outputs.version }}'); - - fs.writeFileSync(outputPath, updatedContent, 'utf8'); - console.log(`Updated action.yml with version ${{ steps.get-version.outputs.version }}`); - - - if: steps.packagejson.outputs.exists == 'true' - name: Commit changes of action.yml - run: | - git commit -am "chore(release): release and bump versions of github action docker" - git push --set-upstream origin ${GITHUB_REF#refs/heads/} || git push origin ${GITHUB_REF#refs/heads/} - if: steps.packagejson.outputs.exists == 'true' name: Publish to any of NPM, Github, and Docker Hub @@ -156,6 +115,9 @@ jobs: uses: changesets/action@v1 id: release with: + version: npm run bump:version + commit: "chore(release): release and bump versions of packages" + title: "chore(release): release and bump versions of packages" publish: npx -p @changesets/cli@2.27.7 changeset publish setupGitUser: false env: diff --git a/.releaserc b/.releaserc deleted file mode 100644 index 1ac05cb151a..00000000000 --- a/.releaserc +++ /dev/null @@ -1,24 +0,0 @@ ---- -branches: -- master -# by default release workflow reacts on push not only to master. -#This is why out of the box sematic release is configured for all these branches -- name: next-spec - prerelease: true -- name: next-major - prerelease: true -- name: next-major-spec - prerelease: true -- name: beta - prerelease: true -- name: alpha - prerelease: true -- name: next - prerelease: true -plugins: -- - "@semantic-release/commit-analyzer" - - preset: conventionalcommits -- - "@semantic-release/release-notes-generator" - - preset: conventionalcommits -- "@semantic-release/npm" -- "@semantic-release/github" diff --git a/github-action/lib/bump-action-version.js b/github-action/lib/bump-action-version.js index 31010b1e6d0..617ebbb33d2 100644 --- a/github-action/lib/bump-action-version.js +++ b/github-action/lib/bump-action-version.js @@ -1,22 +1,18 @@ const fs = require('fs'); const path = require('path'); -module.exports = { - prepare: async (pluginConfig, context) => { - const { nextRelease } = context; - const version = nextRelease.version; +function bumpActionVersion() { + const packageJsonPath = path.join(__dirname, '../../', 'package.json'); + const packageJsonVersion = require(packageJsonPath).version; - const templatePath = path.resolve(__dirname, '../../', 'action-template.yml'); - const outputPath = path.resolve(__dirname, '../../', 'action.yml'); + const templatePath = path.join(__dirname, '../../', 'action-template.yml'); + const outputPath = path.join(__dirname, '../../', 'action.yml'); - try { - const templateContent = fs.readFileSync(templatePath, 'utf8'); - const updatedContent = templateContent.replace(/\${ version }/g, version); - fs.writeFileSync(outputPath, updatedContent, 'utf8'); - console.log(`Updated action.yml with version ${version}`); - } catch (error) { - console.error('Error updating action.yml:', error); - throw error; - } - } -}; + const templateContent = fs.readFileSync(templatePath, 'utf8'); + const updatedContent = templateContent.replace(/\${ version }/g, packageJsonVersion); + + fs.writeFileSync(outputPath, updatedContent, 'utf8'); + console.log(`Updated action.yml with version ${packageJsonVersion}`); +} + +bumpActionVersion(); diff --git a/package.json b/package.json index 0b7ac71f1ce..849ffe85b92 100644 --- a/package.json +++ b/package.json @@ -142,7 +142,8 @@ "repository": "asyncapi/cli", "scripts": { "build": "rimraf lib && node scripts/fetch-asyncapi-example.js && tsc && oclif manifest && echo \"Build Completed\"", - "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", + "bump:github-action": "cd github-action/lib/ && node bump-action-version.js", + "bump:version": "npx -p @changesets/cli@2.27.7 changeset version && npm run bump:github-action", "dev": "tsc --watch", "docker:build": "docker build -t asyncapi/cli:latest .", "generate:readme:create": "node -e \"const fs = require('fs'); fs.writeFileSync('scripts/README.md', '# Usage\\n\\n\\n\\n# Commands\\n\\n\\n');\"", @@ -169,7 +170,6 @@ "createhook": "oclif generate hook myhook --event=command_not_found", "createhookinit": "oclif generate hook inithook --event=init", "action:docker:build": "docker build -f github-action/Dockerfile -t asyncapi/github-action-for-cli:latest .", - "action:bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", "action:test": "cd github-action && make test" }, "types": "lib/index.d.ts"