From ecedcc12ee07e6ff96cff6f1dbe4332cc4d61a51 Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Mon, 7 Oct 2024 17:52:20 -0700 Subject: [PATCH] Added create and push tag and create release --- .../workflows/reusable_image_build_push.yml | 62 ++++++++++++++----- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/.github/workflows/reusable_image_build_push.yml b/.github/workflows/reusable_image_build_push.yml index c0700f743..0b255b9de 100644 --- a/.github/workflows/reusable_image_build_push.yml +++ b/.github/workflows/reusable_image_build_push.yml @@ -39,7 +39,7 @@ jobs: echo "tag_name=$(echo "$response" | jq -r '.tag_name')" >> "$GITHUB_OUTPUT" echo "target_commitish=$(echo "$response" | jq -r '.target_commitish')" >> "$GITHUB_OUTPUT" - - name: Fetch latest server image tag + - name: Fetch current server image tag id: get-server-tag # if: ${{ inputs.repo == 'op-admin-dashboard' || inputs.repo == 'em-public-dashboard' }} if: ${{ inputs.repo == 'op-admin-dashboard' || inputs.repo == 'em-public-dashboard' || inputs.repo == 'nrel-openpath-join-page' }} @@ -53,24 +53,17 @@ jobs: response=$(curl -L -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${{ secrets.GH_FG_PAT_TAGS }}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/MukuFlash03/e-mission-server/git/refs/tags") - # "https://api.github.com/repos/MukuFlash03/e-mission-server/releases/latest") + "https://api.github.com/repos/MukuFlash03/e-mission-server/releases") - # SERVER_IMAGE_TARGET=$(echo "$response" | jq -r '.target_commitish') - # SERVER_IMAGE_TAG=$(echo "$response" | jq -r '.tag_name') + tags=$(echo "$response_r" | jq -r '.[].tag_name') + current_server_release_tag=$(echo "$tags" | sort -V | tail -n 1) + previous_server_release_tag=$(echo "$tags" | sort -V | tail -n 2 | head -n 1) - # echo "SERVER_IMAGE_TAG=$(echo "$response" | jq -r '.tag_name')" >> "$GITHUB_OUTPUT" - # echo "SERVER_IMAGE_TARGET=$(echo "$response" | jq -r '.target_commitish')" >> "$GITHUB_OUTPUT" - - tags=$(echo "$response" | jq -r '.[].ref' | cut -d'/' -f3) - latest_tag=$(echo "$tags" | sort -V | tail -n 1) - previous_tag=$(echo "$tags" | sort -V | tail -n 2 | head -n 1) - - echo "SERVER_IMAGE_TAG=$latest_tag" >> "$GITHUB_OUTPUT" - echo "PREVIOUS_SERVER_TAG=$previous_tag" >> "$GITHUB_OUTPUT" + echo "SERVER_IMAGE_TAG=$current_server_release_tag" >> "$GITHUB_OUTPUT" + echo "PREVIOUS_SERVER_TAG=$previous_server_release_tag" >> "$GITHUB_OUTPUT" - echo "Latest server tag: $latest_tag" - echo "Previous server tag: $previous_tag" + echo "Latest server release tag: $current_server_release_tag" + echo "Previous server release tag: $previous_server_release_tag" - name: Bump up release tag # if: ${{ inputs.repo == 'op-admin-dashboard' || inputs.repo == 'em-public-dashboard' }} @@ -144,11 +137,15 @@ jobs: set -a; source .env; set +a if [ "${{ inputs.repo }}" = "e-mission-server" ]; then echo "SERVER_IMAGE_TAG=${SERVER_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "CURRENT_REPO_TAG=${SERVER_IMAGE_TAG}" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.repo }}" = "nrel-openpath-join-page" ]; then echo "JOIN_IMAGE_TAG=${JOIN_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "CURRENT_REPO_TAG=${JOIN_IMAGE_TAG}" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.repo }}" = "op-admin-dashboard" ]; then echo "ADMIN_DASH_IMAGE_TAG=${ADMIN_DASH_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "CURRENT_REPO_TAG=${ADMIN_DASH_IMAGE_TAG}" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.repo }}" = "em-public-dashboard" ]; then + echo "CURRENT_REPO_TAG=${PUBLIC_DASH_NOTEBOOK_IMAGE_TAG}" >> "$GITHUB_OUTPUT" echo "PUBLIC_DASH_NOTEBOOK_IMAGE_TAG=${PUBLIC_DASH_NOTEBOOK_IMAGE_TAG}" >> "$GITHUB_OUTPUT" echo "PUBLIC_DASH_FRONTEND_IMAGE_TAG=${PUBLIC_DASH_FRONTEND_IMAGE_TAG}" >> "$GITHUB_OUTPUT" fi @@ -291,6 +288,39 @@ jobs: fi cat .env + - name: Create, Push new tag and Publish release + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + git config --local user.email "action@github.com" + git config --local user.name "Github Actions bot to update .env with latest tags" + git tag -a ${{ steps.increment-release-tag.outputs.new_repo_version }} \ + -m “$(git log --pretty=format:%s ${{ steps.set-tags.outputs.CURRENT_REPO_TAG }}…HEAD -—no-merges)“ + + git push origin ${{ steps.increment-release-tag.outputs.new_repo_version }} + + echo "Logging latest created and pushed tag" + git describe --abbrev=0 --tags + + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GH_FG_PAT_TAGS }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/MukuFlash03/${{ inputs.repo }}/releases \ + -d '{"tag_name":${{ steps.increment-release-tag.outputs.new_repo_version }}, \ + "target_commitish":${{ inputs.branch }}, \ + "name":${{ steps.increment-release-tag.outputs.new_repo_version }}, \ + "body":"Triggered on e-mission-server new release. Bumping up release version for ${{ inputs.repo}}", \ + "generate_release_notes":true \ + }' + + echo "Logging latest created release" + latest_release=$(curl -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GH_FG_PAT_TAGS }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/MukuFlash03/${{ inputs.repo }}/releases/latest) + - name: Add, Commit, Push changes to .env file if: ${{ github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' }} run: |