From a3a2a3db801ecf0ae77927552e67394078d138f0 Mon Sep 17 00:00:00 2001 From: Shashank Sinha Date: Thu, 28 Dec 2023 16:59:38 +0400 Subject: [PATCH] PLAT-13282 enable centralized deployment (#380) --- .github/workflows/app-release.yml | 66 ------------------- .../{release.yml => build-deploy.yml} | 21 +----- .github/workflows/create-github-release.yml | 38 +++++++++++ 3 files changed, 41 insertions(+), 84 deletions(-) delete mode 100644 .github/workflows/app-release.yml rename .github/workflows/{release.yml => build-deploy.yml} (52%) create mode 100644 .github/workflows/create-github-release.yml diff --git a/.github/workflows/app-release.yml b/.github/workflows/app-release.yml deleted file mode 100644 index 28f8edd..0000000 --- a/.github/workflows/app-release.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Release - -on: - workflow_dispatch: - -jobs: - - build: - runs-on: ubuntu-latest - env: - working-directory: ./react-native-scaffold - - steps: - - name: Initialize packages - run: | - sudo apt update - sudo apt install jo git -y - - - name: Repo Clone - run: | - git clone https://${{ secrets.GIT_TOKEN }}@github.com/crowdbotics/react-native-scaffold.git - - - name: Checkout branch - working-directory: ${{ env.working-directory }} - run: | - echo "branch: ${GITHUB_REF_NAME}" - git checkout ${GITHUB_REF_NAME} - - - name: Generate Json data - id: data - working-directory: ${{ env.working-directory }} - run: | - r_version="$(curl -s -H "Authorization:token ${{ secrets.GIT_TOKEN }}" https://api.github.com/repos/$GITHUB_REPOSITORY/tags |jq -r '.[].name' |sort |head -1))" - minor=$(echo $r_version | cut -d'.' -f2) - major=$(echo $r_version | cut -d'.' -f1) - if [ $major == $(date '+%Y%m%d') ]; then - tag_version="$(date '+%Y%m%d').$minor" - echo "release version: $tag_version" - until [ $tag_version != $r_version ]; do - let minor++ - tag_version="$(date '+%Y%m%d').$minor" - echo "final release tag: $tag_version" - done - else - tag_version=$(date '+%Y%m%d').1 - echo "final release tag: $tag_version" - fi - jo -p -- -s tag_name="$tag_version" name="Production Release" body="$(git log --oneline --no-decorate HEAD...$(git tag -l '202[0-9]????.*' --sort=-v:refname | head -n 1))" > data.json - continue-on-error: true - - - name: Json Data Status - if: steps.data.outcome == 'failure' - run: exit 1 - - - name: Add Release Notes - working-directory: ${{ env.working-directory }} - run: | - cat data.json - curl -i -X POST -H "Content-Type:application/json" -H "Authorization:token ${{ secrets.GIT_TOKEN }} " https://api.github.com/repos/$GITHUB_REPOSITORY/releases -d @data.json - - - name: Add JIRA Label - working-directory: ${{ env.working-directory }} - run: | - git log --oneline --no-decorate HEAD...$(git tag -l '202[0-9]????.*' --sort=-v:refname | head -n 1) | grep -Eo '([A-Z]{3,}-)([0-9]+)' | uniq > jira_ticket.txt - cat jira_ticket.txt - for i in $(cat jira_ticket.txt); do curl -s -X PUT -H "Content-Type: application/json" -H "Authorization: Basic ${{ secrets.JIRA_TOKEN }}" --data '{"update":{"labels":[{"add":"released"}]}}' https://crowdbotics.atlassian.net/rest/api/3/issue/$i ; done diff --git a/.github/workflows/release.yml b/.github/workflows/build-deploy.yml similarity index 52% rename from .github/workflows/release.yml rename to .github/workflows/build-deploy.yml index 50c093d..e64715b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/build-deploy.yml @@ -1,9 +1,9 @@ -name: Release +name: build-deploy on: push: branches: - - master + - develop tags: - "[0-9]+.[0-9]+" @@ -15,7 +15,7 @@ jobs: steps: - id: setenv run: | - if [ $GITHUB_REF_NAME == master ]; then + if [ $GITHUB_REF_NAME == develop ]; then echo "my_env=staging" >> $GITHUB_OUTPUT fi if [[ $GITHUB_REF_NAME =~ ^[0-9]+\.[0-9]+$ ]]; then @@ -43,18 +43,3 @@ jobs: - name: release scaffold run: | heroku config:set REACT_NATIVE_SCAFFOLD_REPO_BRANCH=$GITHUB_REF_NAME -a ${{ secrets.HEROKU_APP }} - - - name: Checkout - uses: actions/checkout@v3.3.0 - - - name: Add JIRA label - run: | - git fetch --tags - git log --oneline --no-decorate HEAD...$(git tag -l '202[0-9]????.*' --sort=-v:refname | head -n 1) | grep -Eo '([A-Z]{3,}-)([0-9]+)' | uniq > jira_ticket.txt - cat jira_ticket.txt - if [ $GITHUB_REF_NAME == master ]; then - for i in $(cat jira_ticket.txt); do curl -X PUT -H "Content-Type: application/json" -H "Authorization: Basic ${{ secrets.JIRA_TOKEN }}" --data '{"update":{"labels":[{"add":"staging"}]}}' https://crowdbotics.atlassian.net/rest/api/3/issue/$i ; done - fi - if [[ $GITHUB_REF_NAME =~ ^[0-9]+\.[0-9]+$ ]]; then - for i in $(cat jira_ticket.txt); do curl -X PUT -H "Content-Type: application/json" -H "Authorization: Basic ${{ secrets.JIRA_TOKEN }}" --data '{"update":{"labels":[{"add":"released"}]}}' https://crowdbotics.atlassian.net/rest/api/3/issue/$i ; done - fi diff --git a/.github/workflows/create-github-release.yml b/.github/workflows/create-github-release.yml new file mode 100644 index 0000000..bb328bd --- /dev/null +++ b/.github/workflows/create-github-release.yml @@ -0,0 +1,38 @@ +name: create-github-release + +on: + workflow_dispatch: + repository_dispatch: + types: + - create-github-release + +jobs: + + build: + runs-on: ubuntu-latest + env: + working-directory: ./react-native-scaffold + + steps: + - name: Repo Clone + run: | + git clone https://${{ secrets.GIT_TOKEN }}@github.com/crowdbotics/react-native-scaffold.git + + - name: Checkout branch + working-directory: ${{ env.working-directory }} + run: | + if [ ${{ github.event.client_payload.release_branch }} == "master" ]; then + echo "branch: ${{ github.event.client_payload.release_branch }}" + git checkout ${{ github.event.client_payload.release_branch }} + else + echo "manual deployment" + echo "branch: ${GITHUB_REF_NAME}" + git checkout ${GITHUB_REF_NAME} + fi + + - name: Run Release Workflow + uses: crowdbotics/github-actions/create-github-release@master + with: + working-directory: ${{ env.working-directory }} + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} + JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }} \ No newline at end of file