From 89b39a37484a069201c46624bcddfcfd038bf4c8 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Sun, 10 Sep 2023 15:21:03 +0200 Subject: [PATCH 1/3] add info toast for new dev version available --- package.json | 2 +- src/App.js | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 34216ba0..f9668a86 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "scripts": { "start": "react-scripts start", "build": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=false react-scripts build", - "build-netlify": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build", + "build-netlify": "echo $COMMIT_REF > ./public/latest_commit.txt && cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build", "test": "react-scripts test", "analyze-bundle": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true react-scripts build && source-map-explorer 'build/static/js/*.js'", "electron": "yarn electron:before && electron .", diff --git a/src/App.js b/src/App.js index f95e6737..1fb44a5b 100755 --- a/src/App.js +++ b/src/App.js @@ -25,6 +25,7 @@ import useError from "./hooks/useError"; import useInfo from "./hooks/useInfo"; import useSuccess from "./hooks/useSuccess"; import packageJson from '../package.json'; +const commitRef = process?.env?.REACT_APP_COMMIT_REF || ''; export default function App() { const { @@ -70,20 +71,30 @@ export default function App() { try { const packageRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/master/package.json', { cache: 'no-cache' }); const packageData = await packageRes.json(); - + if (packageJson.version !== packageData.version) { const newVersionInfo = `New version available, plebchan v${packageData.version}. Refresh the page to update.`; - localStorage.setItem('infoToast', newVersionInfo);; + localStorage.setItem('infoToast', newVersionInfo); + } + + // Check for commit hash if commitRef is defined + if (commitRef.length > 0) { + const commitRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/development/public/latest_commit.txt', { cache: 'no-cache' }); + const latestCommit = await commitRes.text(); + + if (latestCommit.trim() !== commitRef.trim()) { + const newVersionInfo = `New dev version available, commit ${latestCommit}. Refresh the page to update.`; + localStorage.setItem('infoToast', newVersionInfo); + } } } catch (error) { console.error('Failed to fetch latest version info:', error); } }; - + fetchVersionInfo(); }, [setNewInfoMessage]); - // preload banners useEffect(() => { From ccacb91b8079cd046a2f16a24f4a9a3f4f9a15bb Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Sun, 10 Sep 2023 15:30:16 +0200 Subject: [PATCH 2/3] revert build-netlify script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f9668a86..34216ba0 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "scripts": { "start": "react-scripts start", "build": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=false react-scripts build", - "build-netlify": "echo $COMMIT_REF > ./public/latest_commit.txt && cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build", + "build-netlify": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build", "test": "react-scripts test", "analyze-bundle": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true react-scripts build && source-map-explorer 'build/static/js/*.js'", "electron": "yarn electron:before && electron .", From 3a6bdb6d81375bc1d3418cb5a49240c639c4d80a Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Sun, 10 Sep 2023 15:46:16 +0200 Subject: [PATCH 3/3] add new github action for netlify version --- .github/workflows/latest_dev_commit.yml | 29 +++++++++++++++++++++++++ src/App.js | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/latest_dev_commit.yml diff --git a/.github/workflows/latest_dev_commit.yml b/.github/workflows/latest_dev_commit.yml new file mode 100644 index 00000000..566ff2e5 --- /dev/null +++ b/.github/workflows/latest_dev_commit.yml @@ -0,0 +1,29 @@ +name: Latest Dev Commit + +on: + push: + branches: + - development + +jobs: + update-hash: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get latest commit hash + id: vars + run: echo "::set-output name=commit_hash::$(git rev-parse HEAD)" + + - name: Update latest_dev_commit.txt + run: echo "${{ steps.vars.outputs.commit_hash }}" > ./public/latest_dev_commit.txt + + - name: Commit and push + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add ./public/latest_dev_commit.txt + git commit -m "Update latest_dev_commit.txt with latest commit hash" + git push diff --git a/src/App.js b/src/App.js index 1fb44a5b..a87a1681 100755 --- a/src/App.js +++ b/src/App.js @@ -79,7 +79,7 @@ export default function App() { // Check for commit hash if commitRef is defined if (commitRef.length > 0) { - const commitRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/development/public/latest_commit.txt', { cache: 'no-cache' }); + const commitRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/development/public/latest_dev_commit.txt', { cache: 'no-cache' }); const latestCommit = await commitRes.text(); if (latestCommit.trim() !== commitRef.trim()) {