Skip to content

Commit

Permalink
fix: changeset configuration and github action (#1590)
Browse files Browse the repository at this point in the history
* updated commit for changeset config

* updated changeset github workflow

* updated version command in changeset action
  • Loading branch information
akshatnema authored Dec 13, 2024
1 parent f61e8ed commit 187e7eb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 287 deletions.
134 changes: 0 additions & 134 deletions .github/workflows/if-nodejs-release.yml

This file was deleted.

69 changes: 0 additions & 69 deletions .github/workflows/if-nodejs-version-bump.yml

This file was deleted.

44 changes: 3 additions & 41 deletions .github/workflows/release-with-changesets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,54 +108,16 @@ jobs:
shell: bash
# This step can be removed once the issue is fixed in the changeset package.
run: npm install @changesets/[email protected]
- if: steps.packagejson.outputs.exists == 'true'
name: Get version update from the changeset
uses: changesets/action@v1
with:
version: npx -p @changesets/[email protected] 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: [email protected]
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: [email protected]

- 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
#this step has 2 goals, it is either identifying that there is changeset file created and then this action creates a PR with version bump that will trigger release - or if it sees there is no changeset, and there are versions changes in package.json files, it publish new versions to NPM is they are not there yet
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/[email protected] changeset publish
setupGitUser: false
env:
Expand Down
24 changes: 0 additions & 24 deletions .releaserc

This file was deleted.

30 changes: 13 additions & 17 deletions github-action/lib/bump-action-version.js
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected] 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<!-- usage -->\\n\\n# Commands\\n\\n<!-- commands -->\\n');\"",
Expand All @@ -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"
Expand Down

0 comments on commit 187e7eb

Please sign in to comment.