diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index f7e028e..811675f 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -29,8 +29,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout 🛎️ + uses: actions/checkout@v4.1.3 - name: Detect package manager id: detect-package-manager run: | @@ -74,15 +74,15 @@ jobs: - name: Install dependencies run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} - name: Build with Next.js - run: ${{ steps.detect-package-manager.outputs.runner }} next build + run: ${{ steps.detect-package-manager.outputs.runner }} build && touch ./out/.nojekyll env: NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: ${{ secrets.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN }} # - name: Static HTML export with Next.js # run: ${{ steps.detect-package-manager.outputs.runner }} next export - - name: Upload artifact - uses: actions/upload-pages-artifact@v1 - with: - path: ./out + # - name: Upload artifact + # uses: actions/upload-pages-artifact@v4 + # with: + # path: ./out # Deployment job deploy: @@ -92,6 +92,12 @@ jobs: runs-on: ubuntu-latest needs: build steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 + # - name: Deploy to GitHub Pages + # id: deployment + # uses: actions/deploy-pages@v4 + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@v4.6.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: main + folder: out diff --git a/.gitignore b/.gitignore index 61bae8c..17830af 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ # production /build /.next +out # misc .DS_Store diff --git a/jest.setup.js b/jest.setup.js index 0afb0a0..78be52c 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -2,4 +2,10 @@ import "@testing-library/jest-dom"; import { TextEncoder, TextDecoder } from "util"; +jest.mock("next/config", () => () => ({ + publicRuntimeConfig: { + NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: "https://rekor.sigstore.dev", + }, +})); + Object.assign(global, { TextDecoder, TextEncoder }); diff --git a/next.config.js b/next.config.js index a8c340e..fa57ade 100644 --- a/next.config.js +++ b/next.config.js @@ -7,6 +7,12 @@ const nextConfig = { process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN, }, reactStrictMode: true, + assetPrefix: "./", + images: { + loader: "akamai", + path: "", + }, + output: "export", publicRuntimeConfig: { // remove private env variables processEnv: Object.fromEntries( diff --git a/src/modules/api/context.tsx b/src/modules/api/context.tsx index 298daf9..2693881 100644 --- a/src/modules/api/context.tsx +++ b/src/modules/api/context.tsx @@ -7,6 +7,7 @@ import { useState, } from "react"; import { RekorClient } from "rekor"; +import getConfig from "next/config"; export interface RekorClientContext { client: RekorClient; @@ -22,6 +23,7 @@ export const RekorClientProvider: FunctionComponent> = ({ children, }) => { const [baseUrl, setBaseUrl] = useState(); + const { publicRuntimeConfig } = getConfig(); const context: RekorClientContext = useMemo(() => { /* @@ -31,8 +33,8 @@ export const RekorClientProvider: FunctionComponent> = ({ https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables */ if (baseUrl === undefined) { - if (process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN) { - setBaseUrl(process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN); + if (publicRuntimeConfig.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN) { + setBaseUrl(publicRuntimeConfig.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN); } else { setBaseUrl("https://rekor.sigstore.dev"); } diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index e9e59df..4665e0c 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,8 +1,20 @@ import type { AppProps } from "next/app"; import "@patternfly/react-core/dist/styles/base.css"; +import { NextPageContext } from "next"; function App({ Component, pageProps }: AppProps) { return ; } +App.getInitialProps = async (_ctx: NextPageContext) => { + return { + props: { + NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: process.env + .NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN + ? process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN + : null, + }, // gets passed to the page component as props + }; +}; + export default App; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index aab9bb1..31c24d6 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -112,14 +112,3 @@ const PageComponent: NextPage = () => ( ); export default PageComponent; - -export async function getServerSideProps() { - return { - props: { - NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: process.env - .NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN - ? process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN - : null, - }, // gets passed to the page component as props - }; -}