Skip to content

Commit

Permalink
[Version] ensure version is properly passed to env variable (#443)
Browse files Browse the repository at this point in the history
Closes DG-150

## What changed? Why?
I passed the env variable the wrong way, plus I added more logging to
help in future
  • Loading branch information
dgattey authored Feb 2, 2024
1 parent 5eb343d commit 9a1c6a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
if: ${{ steps.latest-version-tag.outputs.tag != '' }}
run: |
echo "Latest tag: ${LATEST_TAG}"
pnpm vercel build --prod --token=${{ env.VERCEL_DEPLOY_TOKEN }} NEXT_PUBLIC_APP_VERSION="${LATEST_TAG}"
NEXT_PUBLIC_APP_VERSION="${LATEST_TAG}" pnpm vercel build --prod --token=${{ env.VERCEL_DEPLOY_TOKEN }}
env:
LATEST_TAG: ${{ steps.latest-version-tag.outputs.tag }}
- name: Deploy Project Artifacts to Vercel
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build
# misc
.DS_Store
*.pem
.husky

# debug
npm-debug.log*
Expand Down
12 changes: 11 additions & 1 deletion packages/api/github/fetchRepoVersion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { gql } from 'graphql-request';
import { log } from '@logtail/next';
import { githubClient } from './githubClient';
import type { GithubRepoVersionQuery } from './fetchRepoVersion.generated';

Expand Down Expand Up @@ -38,16 +39,25 @@ const QUERY = gql`
export async function fetchRepoVersion(): Promise<string | null> {
const version = process.env.NEXT_PUBLIC_APP_VERSION;
if (version?.length) {
log.info(`Fetching version: using 'NEXT_PUBLIC_APP_VERSION': ${version}`, { version });
return version;
}

// Looks for a release that matches build-time `VERCEL_GIT_COMMIT_SHA` and compares it to each release's commit SHA
// We disable a rule here otherwise the caching gets busted every time
// eslint-disable-next-line turbo/no-undeclared-env-vars
const commitSha = process.env.VERCEL_GIT_COMMIT_SHA;
log.info('Fetching version: no public app version, fetching releases', { commitSha });
const data = await githubClient.request<GithubRepoVersionQuery>(QUERY);
const releases = data.repository?.releases.nodes;
const filteredReleases =
releases?.filter((release) => release?.tagCommit?.oid === commitSha?.trim()) ?? [];
return filteredReleases[0]?.name ?? commitSha?.slice(-12) ?? null;
const foundRelease = filteredReleases[0]?.name;
if (foundRelease) {
log.info('Fetching version: found release', { foundRelease });
return foundRelease;
}

log.info('Fetching version: no release, using commit SHA', { commitSha });
return commitSha?.slice(-12) ?? null;
}

0 comments on commit 9a1c6a2

Please sign in to comment.