diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index 21790e4bfb8..d3484654bac 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -5,7 +5,6 @@ on: - published jobs: - publish-docker: name: Generating Docker runs-on: ubuntu-latest @@ -56,3 +55,45 @@ jobs: pass: ${{ secrets.DOCKER_PASSWORD }} slug: asyncapi/cli description: CLI to work with your AsyncAPI files + + publish-action-docker: + name: Release github action for cli and update version in action.yml + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: master + + - name: Get version without v character + id: version + run: | + VERSION=${{github.event.release.tag_name}} + VERSION_WITHOUT_V=${VERSION:1} + echo "value=${VERSION_WITHOUT_V}" >> $GITHUB_OUTPUT + + - name: Release to Docker + run: | + echo ${{env.DOCKER_PASSWORD}} | docker login -u ${{env.DOCKER_USERNAME}} --password-stdin + npm run action:docker:build + docker tag asyncapi/github-action-for-cli:latest asyncapi/github-action-for-cli:${{ steps.version.outputs.value }} + docker push asyncapi/github-action-for-cli:${{ steps.version.outputs.value }} + docker push asyncapi/github-action-for-cli:latest + + - name: Change directory to github-action + run: | + cd github-action/ + ls -la + + - uses: meeDamian/sync-readme@v1.0.6 + with: + user: ${{ env.DOCKER_USERNAME }} + pass: ${{ env.DOCKER_PASSWORD }} + slug: asyncapi/github-action-for-cli + description: Github action for AsyncAPI CLI + diff --git a/.releaserc b/.releaserc index 1ac05cb151a..4b73d827296 100644 --- a/.releaserc +++ b/.releaserc @@ -1,7 +1,7 @@ --- branches: - master -# by default release workflow reacts on push not only to 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 @@ -20,5 +20,7 @@ plugins: - preset: conventionalcommits - - "@semantic-release/release-notes-generator" - preset: conventionalcommits +- - "./github-action/lib/bump-action-version.js" + - preset: conventionalcommits - "@semantic-release/npm" - "@semantic-release/github" diff --git a/action-template.yml b/action-template.yml new file mode 100644 index 00000000000..40aba410cbb --- /dev/null +++ b/action-template.yml @@ -0,0 +1,54 @@ +name: 'Generator, Validator, Converter and others - all in one for your AsyncAPI docs' +description: 'Use this action to generate docs or code from your AsyncAPI document. Use default templates or provide your custom ones.' +inputs: + cli_version: + description: 'Version of AsyncAPI CLI to be used. This is only needed if you want to test with a specific version of AsyncAPI CLI. Default is latest which is also the recommended option.' + required: false + default: '' + command: + description: 'Command to run. Available commands in action :- generate, validate, convert, optimize and custom. Default is generate. For custom command, provide the whole command as input. List of available commands can be found in https://www.asyncapi.com/docs/tools/cli/usage.' + required: false + default: 'generate' + filepath: + description: 'Path to AsyncAPI document. This input is required if command is set to generate, validate, convert or optimize. Default is ./asyncapi.yaml' + required: false + default: 'asyncapi.yml' + template: + description: 'Template for the generator. Official templates are listed here https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate. You can pass template as npm package, url to git repository, link to tar file or local template.' + default: '@asyncapi/markdown-template@0.10.0' + required: false + language: + description: 'Language of the generated code. This input is required if you want to generate models. List of available languages can be found in https://www.asyncapi.com/docs/tools/cli/usage#asyncapi-generate-models-language-file' + required: false + default: '' + output: + description: 'Directory where to put the generated files. Can be used only with generate or convert commands. Default is output.' + required: false + default: 'output' + parameters: + description: 'The command that you use might support and even require specific parameters to be passed to the CLI for the generation. Template parameters should be preceded by -p' + required: false + default: '' + custom_command: + description: 'Custom command to be run. This input is required if command is set to custom.' + required: false + default: '' + +runs: + using: 'docker' + # This is the image that will be used to run the action. + # IMPORTANT: The version has to be changed manually in your PRs. + image: 'docker://asyncapi/github-action-for-cli:${ version }' + args: + - ${{ inputs.cli_version }} + - ${{ inputs.command }} + - ${{ inputs.filepath }} + - ${{ inputs.template }} + - ${{ inputs.language }} + - ${{ inputs.output }} + - ${{ inputs.parameters }} + - ${{ inputs.custom_command }} + +branding: + icon: 'file-text' + color: purple diff --git a/github-action/lib/bump-action-version.js b/github-action/lib/bump-action-version.js new file mode 100644 index 00000000000..31010b1e6d0 --- /dev/null +++ b/github-action/lib/bump-action-version.js @@ -0,0 +1,22 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + prepare: async (pluginConfig, context) => { + const { nextRelease } = context; + const version = nextRelease.version; + + const templatePath = path.resolve(__dirname, '../../', 'action-template.yml'); + const outputPath = path.resolve(__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; + } + } +};