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