Skip to content

Commit

Permalink
[FIX] Replaced the latest version tag with a baked-in version (#390)
Browse files Browse the repository at this point in the history
* 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 5def864.

* Revert "Grab the last line"

This reverts commit dfcfccb.

* Revert "Installed plugins"

This reverts commit ca0c485.

* Revert "Added GH_TOKEN"

This reverts commit f084501.

* Revert "Let's try using npm"

This reverts commit 602c6a2.

* Revert "Bumped version in `package` files"

This reverts commit 3a99f82.

* Revert "Installed auto as a dev dependency"

This reverts commit 5b9b98d.

* 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 <neurobagel-bot[bot]@users.noreply.github.com>
  • Loading branch information
rmanaem and neurobagel-bot[bot] authored Dec 10, 2024
1 parent 8b29587 commit f3c5210
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

<!-- To be checked off by reviewers -->
## Checklist
_This section is for the PR reviewer_
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/build_docker_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-query-tool",
"private": true,
"version": "0.1.0",
"version": "v0.7.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
20 changes: 3 additions & 17 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useState, useEffect } from 'react';
import axios from 'axios';
import { useState } from 'react';
import {
Toolbar,
Typography,
Expand All @@ -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 | HTMLElement>(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<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
Expand All @@ -52,7 +38,7 @@ function Navbar({ isLoggedIn, onLogin }: { isLoggedIn: boolean; onLogin: () => v
<div className="flex items-center">
<img src={logo} alt="Logo" height="60" />
<div className="ml-4">
<Badge badgeContent={latestReleaseTag}>
<Badge badgeContent={packageJson.version || 'beta'}>
<Typography variant="h5">Neurobagel Query</Typography>
</Badge>
<Typography className="text-gray-500">
Expand Down

0 comments on commit f3c5210

Please sign in to comment.