Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changeset configuration and github action #1590

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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
#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/cli@2.27.7 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/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<!-- 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
Loading