From 37493265747c642d5ca603f2f45bcfb4548b87ca Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:16:53 +0530 Subject: [PATCH] Release branch mech (#187) --- .flake8 | 2 +- .github/workflows/create_release_branch.yaml | 41 ++++++++++++++ .github/workflows/hulk_deployment.yaml | 57 ++++++++++++++++++++ .github/workflows/production_deployment.yml | 5 +- 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/create_release_branch.yaml create mode 100644 .github/workflows/hulk_deployment.yaml diff --git a/.flake8 b/.flake8 index 13a158b8..d4d03545 100644 --- a/.flake8 +++ b/.flake8 @@ -28,4 +28,4 @@ max-line-length = 99 max-complexity = 19 ban-relative-imports = true select = B,C,E,F,N,W,I25 -exclude=*env, *sage_desktop_sdk, *.yml, .flake8, *.txt +exclude=*env, *sage_desktop_sdk, *.yml, .flake8, *.txt, *.yaml diff --git a/.github/workflows/create_release_branch.yaml b/.github/workflows/create_release_branch.yaml new file mode 100644 index 00000000..3c689cd3 --- /dev/null +++ b/.github/workflows/create_release_branch.yaml @@ -0,0 +1,41 @@ +name: Create Release Branch +on: + schedule: + # Run every Friday at 11:30 AM UTC (5:00 PM IST) + - cron: '30 11 * * FRI' +jobs: + create-release-branch: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: master + - name: Get Release Branch Name + run: | + echo "release_branch=sage_desktop_api_release_$(date +%Y_%m_%d)" >> $GITHUB_ENV + echo "last_release_branch=sage_desktop_api_release_$(date -d 'last friday' +%Y_%m_%d)" >> $GITHUB_ENV + - name: Check if release branch exists + run: | + if git ls-remote --exit-code --heads origin ${{env.release_branch}}; then + echo "branch_exists=true" >> $GITHUB_ENV + else + echo "branch_exists=false" >> $GITHUB_ENV + fi + - name: Create release branch + if: ${{env.branch_exists == 'false'}} + run: | + git checkout -b ${{env.release_branch}} + git push origin ${{env.release_branch}} + echo "message=Branch `${{env.release_branch}}` created successfully." >> $GITHUB_ENV + - name: Branch already exists + if: ${{env.branch_exists == 'true'}} + run: echo "message=Branch `${{env.release_branch}}` already exists." >> $GITHUB_ENV + - name: Send message on Slack + uses: archive/github-actions-slack@v2.0.1 + id: notify + with: + # Send message to #integrations slack channel + slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_INTEGRATIONS_OAUTH_ACCESS_TOKEN }} + slack-channel: C074E8V8EL8 + slack-text: "${{env.message}} \nCheck diff here: https://github.com/fylein/fyle-sage-desktop-api/compare/${{env.last_release_branch}}...${{env.release_branch}}" diff --git a/.github/workflows/hulk_deployment.yaml b/.github/workflows/hulk_deployment.yaml new file mode 100644 index 00000000..a3fe775b --- /dev/null +++ b/.github/workflows/hulk_deployment.yaml @@ -0,0 +1,57 @@ +name: Deploy to Hulk + +on: + create: + branches: + - 'sage_desktop_api_release_*' + push: + branches: + - 'sage_desktop_api_release_*' + +jobs: + hulk_deploy: + runs-on: ubuntu-latest + environment: Staging + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Push to dockerhub + uses: fylein/docker-release-action@master + id: generate-and-push-tag + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} + IMAGE_NAME: fyle_sage-desktop-api + + - name: Install kustomize + run: | + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + sudo mv kustomize /usr/local/bin/ + + - name: Clone another repository + uses: actions/checkout@v2 + with: + repository: ${{ vars.STAGING_DEPLOY_REPO }} + ref: master + path: ${{ vars.STAGING_DEPLOY_REPO }} + persist-credentials: false + token: ${{ secrets.DEPLOY_GIT_ACCESS_TOKEN }} + + - name: Update Image Tag + run: | + NEW_TAG=${{ steps.generate-and-push-tag.outputs.new_tag }} + cd ${{ vars.STAGING_DEPLOY_REPO }}/${{ vars.STAGING_DEPLOY_DIR }}/hulk/integrations + kustomize edit set image docker.io/${{ secrets.DOCKERHUB_USERNAME }}/fyle_sage-desktop-api=docker.io/${{ secrets.DOCKERHUB_USERNAME }}/fyle_sage-desktop-api:$NEW_TAG + + - name: Commit and push changes + run: | + NEW_TAG=${{ steps.generate-and-push-tag.outputs.new_tag }} + cd ${{ vars.STAGING_DEPLOY_REPO }} + git config --global user.email "integrations@fylehq.com" + git config --global user.name "GitHub Actions" + git add . + git commit -m "Deployed fyle_sage-desktop-api:$NEW_TAG to hulk" + git remote set-url origin https://x-access-token:${{ secrets.DEPLOY_GIT_ACCESS_TOKEN }}@github.com/${{ vars.STAGING_DEPLOY_REPO }} + git pull origin master + git push origin master diff --git a/.github/workflows/production_deployment.yml b/.github/workflows/production_deployment.yml index bbd66ed6..19a255a4 100644 --- a/.github/workflows/production_deployment.yml +++ b/.github/workflows/production_deployment.yml @@ -14,6 +14,7 @@ jobs: fetch-depth: 0 - name: push to dockerhub uses: fylein/docker-release-action@master + id: generate-and-push-tag env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} @@ -35,7 +36,7 @@ jobs: - name: Update Image Tag run: | - NEW_TAG="v$(git rev-parse --short HEAD)" + NEW_TAG=${{ steps.generate-and-push-tag.outputs.new_tag }} cd ${{ vars.PROD_DEPLOY_REPO }}/${{ vars.PROD_US1_DEPLOY_DIR }}/integrations kustomize edit set image docker.io/${{ secrets.DOCKERHUB_USERNAME }}/fyle_sage-desktop-api=docker.io/${{ secrets.DOCKERHUB_USERNAME }}/fyle_sage-desktop-api:$NEW_TAG @@ -45,7 +46,7 @@ jobs: git config --global user.email "integrations@fylehq.com" git config --global user.name "GitHub Actions" git add . - git commit -m "Update sage-desktop-api image tag" + git commit -m "Deployed fyle_sage-desktop-api:$NEW_TAG to prod" git remote set-url origin https://x-access-token:${{ secrets.DEPLOY_GIT_ACCESS_TOKEN }}@github.com/${{ vars.PROD_DEPLOY_REPO }} git push origin master git push origin master