Skip to content

Commit

Permalink
ci(build): switch from getServerSideProps to getInitialProps (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
kahboom committed Apr 25, 2024
2 parents 4d568d7 + cf3eff3 commit 42884fe
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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:
Expand All @@ -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/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: main
folder: out
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# production
/build
/.next
out

# misc
.DS_Store
Expand Down
6 changes: 6 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/modules/api/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useState,
} from "react";
import { RekorClient } from "rekor";
import getConfig from "next/config";

export interface RekorClientContext {
client: RekorClient;
Expand All @@ -22,6 +23,7 @@ export const RekorClientProvider: FunctionComponent<PropsWithChildren<{}>> = ({
children,
}) => {
const [baseUrl, setBaseUrl] = useState<string>();
const { publicRuntimeConfig } = getConfig();

const context: RekorClientContext = useMemo(() => {
/*
Expand All @@ -31,8 +33,8 @@ export const RekorClientProvider: FunctionComponent<PropsWithChildren<{}>> = ({
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");
}
Expand Down
12 changes: 12 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -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 <Component {...pageProps} />;
}

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;
11 changes: 0 additions & 11 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,3 @@ const PageComponent: NextPage = () => (
</RekorClientProvider>
);
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
};
}

0 comments on commit 42884fe

Please sign in to comment.