From f3c5210637ee938d791f613285737fc241d9d571 Mon Sep 17 00:00:00 2001 From: Arman Jahanpour <77515879+rmanaem@users.noreply.github.com> Date: Tue, 10 Dec 2024 04:29:51 -0500 Subject: [PATCH] [FIX] Replaced the latest version tag with a baked-in version (#390) * Modified `build_docker_nightly` workflow * Set `GH_TOKEN` * A different approach * Use shortened sha * Updated `build_docker_on_release` workflow * Updated `deploy` workflow * Removed fetching version from GitHub * Fixed typo * Reverted changes made to `deploy` workflow * Added `bump_version` workflow * Updated `bump_version` workflow * Added the labeled type * Test different auto commands * comment out the label condition * Try canary command * Added github token * Let's try commands * let's try this solution * Removed couple steps * Set the version_schema * Remove prerelease_suffix * Removed default field * Trying the latest version * seems silly but worth a try * Installed auto as a dev dependency * Bumped version in `package` files * Let's try using npm * Added GH_TOKEN * Installed plugins * Grab the last line * Installed the npm plugin explicitly * Revert "Installed the npm plugin explicitly" This reverts commit 5def864b0b691023d39f586e09a12a5d7b6c3970. * Revert "Grab the last line" This reverts commit dfcfccb79c5f8ac36a826d673a63053bb6dc940b. * Revert "Installed plugins" This reverts commit ca0c485d13ce86333e919d11594b4c270f6beffa. * Revert "Added GH_TOKEN" This reverts commit f0845016a0393ea1bd75ac57b4b0b256b3ddda22. * Revert "Let's try using npm" This reverts commit 602c6a2338ad614c47782041a3f6c5cdfbf12bf2. * Revert "Bumped version in `package` files" This reverts commit 3a99f826ccfc85604d04958ac7b360a69b69ff81. * Revert "Installed auto as a dev dependency" This reverts commit 5b9b98d4cd6d6903427b8baa85d0f01d8502d92a. * Going back to version * Let's see the output * Read in a separate step * Let's try this * try again * Try verbose logs * Really? * ok does this work too? * Getting there * Forgot the GH_TOKEN again * Fixed the missing version * Let's run on pull_request * GH_TOKEN added * Almost there * Try a fix for committing to the same branch * figuring out the right syntax * an alternative appraoch * Let's see what's in there * Let's check this one out * This should do it * It's possible we didn't even needed the branch name * Try this syntax * Bumped version to v0.7.2 * Added a condition to check diff before commiting * Refactor * Added a condition to skip the workflow when increment is empty * Small refactor * Removed the explicit condition and used label condition * Bumped version to v0.7.2 * Updated `pull_request_template` * Reverted changes made to `build_docker_on_release` * Fixed typo --------- Co-authored-by: Neurobagel Bot --- .github/pull_request_template.md | 2 + .github/workflows/build_docker_nightly.yml | 13 ++++ .github/workflows/bump_version.yml | 90 ++++++++++++++++++++++ package.json | 2 +- src/components/Navbar.tsx | 20 +---- 5 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/bump_version.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index b28ca796..187d097a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -25,6 +25,8 @@ Changes proposed in this pull request: - - +**NOTE: If this pull request is to be released, the release label must be applied once the review process is done to avoid the local and remote from going out of sync as a consequence of the `bump version` workflow run** + ## Checklist _This section is for the PR reviewer_ diff --git a/.github/workflows/build_docker_nightly.yml b/.github/workflows/build_docker_nightly.yml index 44fb74d2..3a9613e9 100644 --- a/.github/workflows/build_docker_nightly.yml +++ b/.github/workflows/build_docker_nightly.yml @@ -16,6 +16,19 @@ jobs: with: submodules: recursive + - name: Fetch latest commit SHA from main branch + id: fetch_sha + run: | + git fetch origin main + LATEST_SHA=$(git rev-parse --short=7 origin/main) + echo "LATEST_SHA=$LATEST_SHA" >> $GITHUB_ENV + + - name: Update package.json version + run: | + SHA=${{ env.LATEST_SHA }} + jq ".version = \"build:${SHA}\"" package.json > tmp.$$.json && mv tmp.$$.json package.json + cat package.json + - name: Login to Docker Hub uses: docker/login-action@v3 with: diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml new file mode 100644 index 00000000..39b23f12 --- /dev/null +++ b/.github/workflows/bump_version.yml @@ -0,0 +1,90 @@ +name: bump version + +on: + pull_request: + types: [labeled] + workflow_dispatch: + +permissions: + contents: write + pull-requests: write # Required to commit changes to PR branches + +jobs: + bump-version: + runs-on: ubuntu-latest + if: ${{ github.event.label.name == 'release' }} + steps: + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.NB_BOT_ID }} + private-key: ${{ secrets.NB_BOT_KEY }} + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ steps.generate-token.outputs.token }} + + - name: Download latest auto + run: | + auto_download_url="$(curl -fsSL https://api.github.com/repos/intuit/auto/releases/latest | jq -r '.assets[] | select(.name == "auto-linux.gz") | .browser_download_url')" + wget -O- "$auto_download_url" | gunzip > ~/auto + chmod a+x ~/auto + + - name: Get latest release version + id: latest-release + run: | + LATEST_TAG=$(curl -fsSL https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV + + - name: Compute increment + id: compute-increment + run: | + # Run auto to determine version increment (patch, minor, major) + INCREMENT=$(~/auto version) + echo "Increment: $INCREMENT" + echo "INCREMENT=$INCREMENT" >> $GITHUB_ENV + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + + - name: Bump version + id: bump-version + run: | + # Extract the current version from the latest release + VERSION=${{ env.LATEST_TAG }} + VERSION=${VERSION#v} # Remove the "v" prefix if it exists + + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" + + # Increment based on the auto output + if [ "${{ env.INCREMENT }}" == "major" ]; then + ((MAJOR++)) + MINOR=0 + PATCH=0 + elif [ "${{ env.INCREMENT }}" == "minor" ]; then + ((MINOR++)) + PATCH=0 + elif [ "${{ env.INCREMENT }}" == "patch" ]; then + ((PATCH++)) + fi + + # Construct the new version + NEW_VERSION="v$MAJOR.$MINOR.$PATCH" + echo "New version: $NEW_VERSION" + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + + - name: Update package.json + run: | + jq ".version = \"$NEW_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + + - name: Commit and Push Changes + run: | + git config --global user.name "Neurobagel Bot" + git config --global user.email "neurobagel-bot[bot]@users.noreply.github.com" + git diff --quiet package.json || (git add package.json && git commit -m "Bumped version to $NEW_VERSION" && git push origin HEAD:${{ github.head_ref }}) + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} diff --git a/package.json b/package.json index bc52dfb3..52eacadf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-query-tool", "private": true, - "version": "0.1.0", + "version": "v0.7.2", "type": "module", "scripts": { "dev": "vite", diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 69fdeda1..ef2c35df 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,5 +1,4 @@ -import { useState, useEffect } from 'react'; -import axios from 'axios'; +import { useState } from 'react'; import { Toolbar, Typography, @@ -17,28 +16,15 @@ import Login from '@mui/icons-material/Login'; import Avatar from '@mui/material/Avatar'; import { useAuth0 } from '@auth0/auth0-react'; import { enableAuth } from '../utils/constants'; +import packageJson from '../../package.json'; import logo from '../assets/logo.png'; function Navbar({ isLoggedIn, onLogin }: { isLoggedIn: boolean; onLogin: () => void }) { - const [latestReleaseTag, setLatestReleaseTag] = useState(''); const [anchorEl, setAnchorEl] = useState(null); const openAccountMenu = Boolean(anchorEl); const { user, logout } = useAuth0(); - useEffect(() => { - const GHApiURL = 'https://api.github.com/repos/neurobagel/query-tool/releases/latest'; - axios - .get(GHApiURL) - .then((response) => { - const { data } = response; - setLatestReleaseTag(data.tag_name); - }) - .catch(() => { - setLatestReleaseTag('beta'); - }); - }, []); - const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; @@ -52,7 +38,7 @@ function Navbar({ isLoggedIn, onLogin }: { isLoggedIn: boolean; onLogin: () => v
Logo
- + Neurobagel Query