diff --git a/.github/workflows/create-hotfix-branch.yml b/.github/workflows/create-hotfix-branch.yml new file mode 100644 index 0000000..af32dd8 --- /dev/null +++ b/.github/workflows/create-hotfix-branch.yml @@ -0,0 +1,23 @@ +name: Create New Hotfix Branch + +on: + workflow_dispatch: + inputs: + hotfix_name: + description: Hotfix branch name + required: true + +jobs: + create-branch: + name: Create New Hotfix Branch + runs-on: ubuntu-latest + + # Only allow these users to create new hotfix branch from 'main' + if: github.ref == 'refs/heads/main' && (github.actor == 'ItsSudip' || github.actor == 'krishna2020' || github.actor == 'utsabc' || github.actor == 'shrouti1507') && (github.triggering_actor == 'ItsSudip' || github.triggering_actor == 'krishna2020' || github.triggering_actor == 'shrouti1507' || github.triggering_actor == 'utsabc') + steps: + - name: Create Branch + uses: peterjgrainger/action-create-branch@v2.4.0 + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + with: + branch: 'hotfix/${{ inputs.hotfix_name }}' diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml new file mode 100644 index 0000000..a6171e2 --- /dev/null +++ b/.github/workflows/draft-new-release.yml @@ -0,0 +1,88 @@ +name: Draft New Release + +on: workflow_dispatch + +jobs: + draft-new-release: + name: Draft New Release + runs-on: ubuntu-latest + + # Only allow release stakeholders to initiate releases + if: (github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/hotfix/')) && (github.actor == 'ItsSudip' || github.actor == 'krishna2020' || github.actor == 'utsabc' || github.actor == 'shrouti1507') && (github.triggering_actor == 'ItsSudip' || github.triggering_actor == 'krishna2020' || github.triggering_actor == 'utsabc' || github.triggering_actor == 'shrouti1507') + steps: + - name: Checkout + uses: actions/checkout@v4.1.0 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v4.0.1 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Install Dependencies + env: + HUSKY: 0 + run: | + npm ci + + # In order to make a commit, we need to initialize a user. + # You may choose to write something less generic here if you want, it doesn't matter functionality wise. + - name: Initialize Mandatory Git Config + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "noreply@github.com" + + # Calculate the next release version based on conventional semantic release + - name: Create Release Branch + id: create-release + env: + HUSKY: 0 + run: | + source_branch_name=${GITHUB_REF##*/} + release_type=release + grep -q "hotfix/" <<< "${GITHUB_REF}" && release_type=hotfix-release + git fetch origin main + git fetch --tags origin + git merge origin/main + current_version=$(jq -r .version package.json) + + npm run release -- --skip.commit --skip.tag --skip.changelog + new_version=$(jq -r .version package.json) + git reset --hard + + branch_name="${release_type}/v${new_version}" + + echo "Source branch for new release is $source_branch_name" + echo "Current version is $current_version" + echo "Release type is $release_type" + echo "New version is $new_version" + echo "New release branch name is $branch_name" + git checkout -b "$branch_name" + git push --set-upstream origin "$branch_name" + + echo "source_branch_name=$source_branch_name" >> $GITHUB_OUTPUT + echo "branch_name=$branch_name" >> $GITHUB_OUTPUT + echo "new_version=$new_version" >> $GITHUB_OUTPUT + echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV + echo "NEW_VERSION_VALUE=$new_version" >> $GITHUB_ENV + + - name: Update Changelog & Bump Version + id: finish-release + env: + HUSKY: 0 + run: | + echo "Current version: $CURRENT_VERSION_VALUE" + echo "New version: $NEW_VERSION_VALUE" + npm run release -- -a --skip.tag --no-verify + git push + + - name: Create Pull Request + uses: repo-sync/pull-request@v2.12.1 + with: + source_branch: ${{ steps.create-release.outputs.branch_name }} + destination_branch: 'main' + github_token: ${{ secrets.PAT }} + pr_title: 'chore(release): pull ${{ steps.create-release.outputs.branch_name }} into main' + pr_body: ':crown: *An automated PR*' diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml index 0e16a1b..708eb32 100644 --- a/.github/workflows/prod-deploy.yml +++ b/.github/workflows/prod-deploy.yml @@ -1,14 +1,12 @@ name: Docker Image CI for shopify-tracker on: - workflow_call: - secrets: - DOCKERHUB_USERNAME: - required: true - DOCKERHUB_TOKEN: - required: true - PAT: - required: true - description: Personal access token to be used for cloning rudder-devops + push: + branches: [main] + pull_request: + types: + - closed + branches: + - main permissions: read-all @@ -16,6 +14,7 @@ jobs: extract-version: name: Extract Version runs-on: ubuntu-latest + if: ((startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix-release/')) && github.event.pull_request.merged == true) outputs: version: ${{ steps.get-version.outputs.version }} @@ -29,11 +28,12 @@ jobs: id: get-version run: | version=$(jq -r .version package.json) - echo "Version: $version" + echo "Version: $version" echo "version=$version" >> $GITHUB_OUTPUT build: name: Build Shopify Tracker Docker Image + if: ((startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix-release/')) && github.event.pull_request.merged == true) needs: [extract-version] uses: ./.github/workflows/build-and-push-docker-image.yml with: diff --git a/.github/workflows/publish-new-release.yml b/.github/workflows/publish-new-release.yml new file mode 100644 index 0000000..d52cb93 --- /dev/null +++ b/.github/workflows/publish-new-release.yml @@ -0,0 +1,121 @@ +name: Publish New GitHub Release + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + release: + name: Publish New GitHub Release + runs-on: ubuntu-latest + + if: (startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix-release/')) && github.event.pull_request.merged == true # only merged pull requests must trigger this job + + steps: + - name: Extract Version + id: extract-version + run: | + branch_name="${{ github.event.pull_request.head.ref }}" + version=${branch_name#hotfix-} + version=${version#release/v} + + echo "release_version=$version" >> $GITHUB_OUTPUT + + - name: Checkout + uses: actions/checkout@v4.1.0 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v4.0.1 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Install Dependencies + env: + HUSKY: 0 + run: | + npm ci + + # In order to make a commit, we need to initialize a user. + # You may choose to write something less generic here if you want, it doesn't matter functionality wise. + - name: Initialize Mandatory Git Config + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "noreply@github.com" + + - name: Tag & Create GitHub Release + id: create_release + env: + HUSKY: 0 + GITHUB_TOKEN: ${{ secrets.PAT }} + CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.PAT }} + run: | + git fetch --tags origin + git tag -a v${{ steps.extract-version.outputs.release_version }} -m "chore: release v${{ steps.extract-version.outputs.release_version }}" + git push origin refs/tags/v${{ steps.extract-version.outputs.release_version }} + npm run release:github + echo "DATE=$(date)" >> $GITHUB_ENV + + - name: Pull Changes Into develop Branch + uses: repo-sync/pull-request@v2.12.1 + with: + source_branch: 'main' + destination_branch: 'develop' + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_title: 'chore(release): pull main into develop post release v${{ steps.extract-version.outputs.release_version }}' + pr_body: ':crown: *An automated PR*' + + - name: Delete Release Branch + uses: koj-co/delete-merged-action@master + if: startsWith(github.event.pull_request.head.ref, 'release/') + with: + branches: 'release/*' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Delete Hotfix Release Branch + uses: koj-co/delete-merged-action@master + if: startsWith(github.event.pull_request.head.ref, 'hotfix-release/') + with: + branches: 'hotfix-release/*' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Notify Slack Channel + id: slack + uses: slackapi/slack-github-action@v1.24.0 + continue-on-error: true + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + PROJECT_NAME: 'Rudder Shopify Tracker' + RELEASES_URL: 'https://github.com/rudderlabs/rudder-shopify-tracker/releases/tag/' + with: + channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }} + payload: | + { + "text": "*<${{env.RELEASES_URL}}v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\nCC: <@U03KG4BK1L1> <@U01LVJ30QEB> <@U01FG952S8Y>", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": ":tada: ${{ env.PROJECT_NAME }} - New GitHub Release :tada:" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*<${{env.RELEASES_URL}}v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\nCC: <@U03KG4BK1L1> <@U01LVJ30QEB> <@U01FG952S8Y>" + } + } + ] + } diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml deleted file mode 100644 index 5a6c315..0000000 --- a/.github/workflows/release-please.yml +++ /dev/null @@ -1,87 +0,0 @@ -on: - push: - branches: - - 'main' - -name: release-please - -jobs: - release-please: - runs-on: ubuntu-latest - outputs: - release_created: ${{ steps.release.outputs.release_created }} - steps: - - name: Extract Branch Name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: extract_branch - - - uses: google-github-actions/release-please-action@v3 - id: release - with: - token: ${{ github.token }} - pull-request-title-pattern: 'chore: release ${version}' - release-type: node - package-name: 'rudder-shopify-tracker' - default-branch: ${{ steps.extract_branch.outputs.branch }} - changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false},{"type":"refactor","section":"Miscellaneous","hidden":false},{"type":"test","section":"Miscellaneous","hidden":false},{"type":"doc","section":"Documentation","hidden":false}]' - bump-minor-pre-major: true - bump-patch-for-minor-pre-major: true - - production-release: - name: Make production release for shopify-tracker - needs: [release-please] - if: ${{ needs.release-please.outputs.release_created }} - uses: ./.github/workflows/prod-deploy.yml - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - PAT: ${{ secrets.PAT }} - - post-release-to-prod: - name: Post release actions - runs-on: ubuntu-latest - needs: [release-please, release-to-prod] - if: ${{ needs.release-please.outputs.release_created }} - steps: - - name: Delete Release Branch - uses: koj-co/delete-merged-action@master - if: startsWith(github.event.pull_request.head.ref, 'release-please--branches') - with: - branches: 'release-please--branches*' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Notify Slack Channel - id: slack - uses: slackapi/slack-github-action@v1.24.0 - continue-on-error: true - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - PROJECT_NAME: 'Rudder Shopify Tracker' - RELEASES_URL: 'https://github.com/rudderlabs/rudder-shopify-tracker/releases/tag/' - with: - channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }} - payload: | - { - "text": "*<${{env.RELEASES_URL}}v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\nCC: <@U03KG4BK1L1> <@U01LVJ30QEB> <@U01FG952S8Y>", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":tada: ${{ env.PROJECT_NAME }} - New GitHub Release :tada:" - } - }, - { - "type": "divider" - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*<${{env.RELEASES_URL}}v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\nCC: <@U03KG4BK1L1> <@U01LVJ30QEB> <@U01FG952S8Y>" - } - } - ] - }