diff --git a/.github/actions/bump-version/action.yml b/.github/actions/bump-version/action.yml new file mode 100644 index 00000000..b5734fd9 --- /dev/null +++ b/.github/actions/bump-version/action.yml @@ -0,0 +1,39 @@ +name: Publish Workflow / Bump version +description: It bump version of provided package + +inputs: + version: + description: | major | minor | patch | premajor | preminor | prepatch | prerelease + required: true + npm_tag: + description: tag for NPM artifact + required: false + +outputs: + prev_version: + value: ${{ steps.internal_id_prev_version.outputs.value }} + next_version: + value: ${{ steps.internal_id_next_version.outputs.value }} + +runs: + using: composite + steps: + - name: Saving current version to env + id: internal_id_prev_version + run: echo "value=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + shell: bash + + - name: Bump version + if: ${{ !inputs.npm_tag }} + run: yarn version --new-version "${{ inputs.version }}" --no-commit-hooks + shell: bash + + - name: Bump version with npm_tag + if: ${{ inputs.npm_tag }} + run: yarn version --new-version "${{ inputs.version }}" --preid ${{ inputs.npm_tag }} --no-commit-hooks + shell: bash + + - name: Saving new version to env + id: internal_id_next_version + run: echo "value=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + shell: bash diff --git a/.github/actions/complete-publish/action.yml b/.github/actions/complete-publish/action.yml new file mode 100644 index 00000000..d5b24814 --- /dev/null +++ b/.github/actions/complete-publish/action.yml @@ -0,0 +1,48 @@ +name: Publish Workflow / Complete +description: It finish publishing + +inputs: + branch: + description: target branch for git push + required: true + prev_version: + description: package's prev version + required: true + next_version: + description: package's next version + required: true + npm_tag: + description: tag for NPM artifact + required: false + token: + description: token for write access to repository + required: true + npm_token: + description: token for publish package to NPM + +runs: + using: composite + steps: + - name: Create tag + run: git tag vk-mini-apps-router@${{ inputs.next_version }} + shell: bash + + - name: Pushing changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ inputs.token }} + branch: ${{ inputs.branch }} + + - name: Publishing release + if: ${{ !inputs.npm_tag }} + run: yarn publish --access public --non-interactive + env: + NODE_AUTH_TOKEN: ${{ inputs.npm_token }} + shell: bash + + - name: Publishing release with npm_tag + if: ${{ inputs.npm_tag }} + run: yarn publish --access public --non-interactive --tag ${{ inputs.npm_tag }} + env: + NODE_AUTH_TOKEN: ${{ inputs.npm_token }} + shell: bash diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 00000000..9f86008f --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,23 @@ +name: Publish Workflow / Setup +description: It setting up the repository environment for publish + +runs: + using: composite + steps: + - name: Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'yarn' + always-auth: true + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: yarn install --frozen-lockfile --ignore-scripts + shell: bash + + - name: Set Git credentials + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Action" + shell: bash diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ac6b09d0..557c1b52 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,42 +3,41 @@ name: 'Publish' on: workflow_dispatch: inputs: - version: - description: 'version (without v prefix)' + new_version: + description: 'version type:' + type: choice + default: 'minor' + options: + - patch + - minor + - major required: true +run-name: Publish vk-mini-apps-router ${{ inputs.new_version }} + jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }} - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: 'yarn' - always-auth: true - registry-url: 'https://registry.npmjs.org' - - - name: Install dependencies - run: yarn install --frozen-lockfile --ignore-scripts - - - name: Set Git credentials - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Action" + - name: Setting up the repository environment + uses: ./.github/actions/setup - - run: yarn version --new-version ${{ github.event.inputs.version }} --no-commit-hooks + - name: Bump version + id: updated_versions_info + uses: ./.github/actions/bump-version + with: + version: ${{ github.event.inputs.new_version }} - - name: Pushing changes - uses: ad-m/github-push-action@master + - name: Complete publish + uses: ./.github/actions/complete-publish with: - github_token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }} branch: ${{ github.ref }} - - - name: Publishing release - run: yarn publish --access public --non-interactive - env: - NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLISH_TOKEN }} + prev_version: ${{ steps.updated_versions_info.outputs.prev_version }} + next_version: ${{ steps.updated_versions_info.outputs.next_version }} + token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }} + npm_token: ${{ secrets.NPMJS_PUBLISH_TOKEN }} diff --git a/.github/workflows/publish_prerelease.yml b/.github/workflows/publish_prerelease.yml new file mode 100644 index 00000000..a0dec439 --- /dev/null +++ b/.github/workflows/publish_prerelease.yml @@ -0,0 +1,58 @@ +name: 'Publish (pre-release)' + +on: + workflow_dispatch: + inputs: + new_version: + description: 'version type (use prerelease for bumping pre-release version):' + required: true + type: choice + default: 'prerelease' + options: + - prepatch + - preminor + - premajor + - prerelease + npm_tag: + required: true + description: 'NPM tag:' + type: choice + default: 'beta' + options: + - alpha + - beta + - rc + custom_version: + description: 'use syntax x.y.z-beta.0, without "v" (it ignore "version type" parameter):' + required: false + +run-name: Publish ${{ inputs.new_version }} vk-mini-apps-router ${{ inputs.custom_version }} + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }} + + - name: Setting up the repository environment + uses: ./.github/actions/setup + + - name: Bump version + id: updated_versions_info + uses: ./.github/actions/bump-version + with: + version: ${{ github.event.inputs.custom_version || github.event.inputs.new_version }} + npm_tag: ${{ github.event.inputs.npm_tag }} + + - name: Complete publish + uses: ./.github/actions/complete-publish + with: + branch: ${{ github.ref }} + prev_version: ${{ steps.updated_versions_info.outputs.prev_version }} + next_version: ${{ steps.updated_versions_info.outputs.next_version }} + npm_tag: ${{ github.event.inputs.npm_tag }} + token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }} + npm_token: ${{ secrets.NPMJS_PUBLISH_TOKEN }}