From ca3dfb618ecf6e19ea7c282b7ecec9ce30281487 Mon Sep 17 00:00:00 2001 From: Niv Ezra Date: Fri, 12 Jan 2024 20:26:54 +0200 Subject: [PATCH] added CI with interactive inputs action --- .github/workflows/ci.yaml | 121 +++++++++++++++++++++++++++++ .github/workflows/manual-bump.yaml | 36 --------- .github/workflows/publish.yaml | 42 ---------- 3 files changed, 121 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/manual-bump.yaml delete mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..829813e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,121 @@ +name: Bump and Release +on: + push: + branches: + - '**' + +permissions: + contents: write + +jobs: + bump-choice: + runs-on: ubuntu-latest + outputs: + user-choice: ${{ steps.bump-input.outputs.user-choice }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Get bump input from Telegram + id: bump-input + uses: NivEz/interactive-inputs-action@v1 + with: + telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }} + telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }} + question: 'Updating Telenode. Which bump type you wish to perform?' + options: '["prerelease", "patch", "minor", "major", "skip"]' + default-choice: 'skip' + message: 'The selected bump type is: %s' + timeout: 45 + wait-for-timeout-to-finish: true + + bump: + runs-on: ubuntu-latest + needs: bump-choice + if: needs.bump-choice.outputs.user-choice != 'skip' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup git config + run: | + git config user.name "GitHub Actions" + git config user.email "${{ secrets.GIT_CONFIG_EMAIL }}" + + - name: Bump version + run: npm version ${{ needs.bump-choice.outputs.user-choice }} -m "v%s" + + - name: Push + run: git push --follow-tags + + - name: Build success message + id: success-message + run: | + latest-tag="$(git describe --abbrev=0 --tags)" + message="Successfully bumped ${{ needs.bump-choice.outputs.user-choice }} update: $latest-tag" + echo $message + echo "message=$message" >> $GITHUB_OUTPUT + + - name: Send message + uses: NivEz/interactive-inputs-action@v1 + with: + telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }} + telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }} + simple-message: ${{ steps.success-message.outputs.message }} + + publish-choice: + runs-on: ubuntu-latest + needs: bump + outputs: + user-choice: ${{ steps.publish-input.outputs.user-choice }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Check if should publish + id: publish-input + uses: NivEz/interactive-inputs-action@v1 + with: + telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }} + telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }} + question: 'Should publish to npm?' + options: '["yes", "no"]' + default-choice: 'no' + message: 'The selected choice is: %s' + timeout: 45 + wait-for-timeout-to-finish: true + + publish: + runs-on: ubuntu-latest + needs: publish-choice + if: needs.publish-choice.outputs.user-choice == 'yes' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Publish package to npm + id: publish + uses: JS-DevTools/npm-publish@v1 + with: + token: ${{ secrets.NPM_TOKEN }} + + - name: Create Github release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.publish.outputs.version }} + generateReleaseNotes: true + + - name: Success message + uses: NivEz/interactive-inputs-action@v1 + with: + telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }} + telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }} + simple-message: 'Successfully published a new version: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}' + + - name: Failure message + if: failure() + uses: NivEz/interactive-inputs-action@v1 + with: + telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }} + telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }} + simple-message: 'Failure occurred with the new version ${{ steps.publish.outputs.version }}' diff --git a/.github/workflows/manual-bump.yaml b/.github/workflows/manual-bump.yaml deleted file mode 100644 index 9867308..0000000 --- a/.github/workflows/manual-bump.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Manual bump -on: - workflow_dispatch: - branches: - - '**' - inputs: - bump: - description: 'Choose a bump type' - type: choice - options: - - prerelease - - patch - - minor - - major - default: patch - -permissions: - contents: write - -jobs: - bump: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup git config - run: | - git config user.name "GitHub Actions" - git config user.email "${{ secrets.GIT_CONFIG_EMAIL }}" - - - name: Bump version - run: npm version ${{ inputs.bump }} -m "v%s" - - - name: Push - run: git push --follow-tags diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index e45bdfa..0000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Publish package to NPM -on: - workflow_dispatch: - branches: - - main - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Publish package to NPM - id: publish - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ secrets.NPM_TOKEN }} - - - name: Log update - if: steps.publish.outputs.type != 'none' - run: | - echo Successfully published a new version - echo "${{ steps.publish.outputs.type }} update: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}" - - github-release: - runs-on: ubuntu-latest - needs: publish - permissions: - contents: write - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Get package version - run: echo "LATEST_TAG=$(jq -r .version package.json)" >> $GITHUB_ENV - - - name: Create Github release - uses: ncipollo/release-action@v1 - with: - tag: 'v${{ env.LATEST_TAG }}' - generateReleaseNotes: true