From 0a42b93e511e82ba70c6a4b508307489fbac1efa Mon Sep 17 00:00:00 2001 From: Viraj Chitnis Date: Sat, 3 Jun 2017 11:54:28 -0400 Subject: [PATCH] Tag releases and have the server checkout the latest release Closes #36 --- githook.sh | 6 +++++- routes/api.js | 4 ++-- routes/endpoints.js | 2 +- src/common/components/Footer/Footer.jsx | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/githook.sh b/githook.sh index ec839a9..995d700 100755 --- a/githook.sh +++ b/githook.sh @@ -3,6 +3,10 @@ export PATH="/root/.nvm/versions/node/v6.10.1/bin:${PATH}" git fetch origin -git checkout --force origin/master +git fetch --tags +latesttag=$(git describe --tags `git rev-list --tags --max-count=1`) +echo Deploying ${latesttag} +git checkout --force ${latesttag} + yarn redeploy ./node_modules/forever/bin/forever restartall diff --git a/routes/api.js b/routes/api.js index 3d750eb..3ee0f3b 100644 --- a/routes/api.js +++ b/routes/api.js @@ -9,8 +9,8 @@ router.get('/gitcommit', function (req, res){ const apikey = req.headers['api-key']; if (apikey == configJSON.api_key) { newDevice('_vcid', res, req, configJSON.mailgun_api_key, configJSON.authorized_device_secret); - exec('git rev-parse HEAD', function(err, stdout) { - const commitId = stdout.substring(0,7); + exec('git tag -l --points-at HEAD', function(err, stdout) { + const commitId = stdout; res.status(200).send({ commit_id: commitId, updated_at: configJSON.last_start_time diff --git a/routes/endpoints.js b/routes/endpoints.js index 0f6be34..6ff8d88 100644 --- a/routes/endpoints.js +++ b/routes/endpoints.js @@ -12,7 +12,7 @@ router.post('/githook', function (req, res) { hmac.update(JSON.stringify(req.body)); computedHubSig = hmac.digest('hex'); if (xHubSig == computedHubSig) { - if (req.body.ref == "refs/heads/master") { + if (req.body.ref.startsWith("refs/tags/")) { function puts(error, stdout, stderr) { sys.puts(stdout) } exec("./githook.sh", puts); res.send({ diff --git a/src/common/components/Footer/Footer.jsx b/src/common/components/Footer/Footer.jsx index f800433..824a4ab 100644 --- a/src/common/components/Footer/Footer.jsx +++ b/src/common/components/Footer/Footer.jsx @@ -74,7 +74,7 @@ export default class Footer extends React.Component { let formattedDate = ''; if (commit_id != '') { - commitURL = "https://github.com/virajchitnis/virajchitnis.com/commit/" + commit_id; + commitURL = "https://github.com/virajchitnis/virajchitnis.com/tree/" + commit_id; formattedDate = new Date(updated_at).toLocaleTimeString("en-us", options); commitFooter = (