Skip to content

Commit

Permalink
fix: remove authToken to build the ts-lib and remove github access to…
Browse files Browse the repository at this point in the history
…ken env variable from CI workflows (#18)

Co-authored-by: Pedro Novais <[email protected]>
  • Loading branch information
VGau and jpnovais authored Sep 12, 2024
1 parent 0cc4d6d commit 81affa3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
1 change: 0 additions & 1 deletion .github/workflows/postman-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ jobs:
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
build-args: |
GITHUB_API_ACCESS_TOKEN=${{ secrets._GITHUB_TOKEN_RELEASE_ACCESS }}
NATIVE_LIBS_RELEASE_TAG=blob-libs-v1.0.1
1 change: 0 additions & 1 deletion .github/workflows/postman-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:

- name: Run tests and generate coverage report
env:
GITHUB_API_ACCESS_TOKEN: ${{ secrets._GITHUB_TOKEN_RELEASE_ACCESS }}
NATIVE_LIBS_RELEASE_TAG: blob-libs-v1.0.1
run: |
pnpm run -F ./ts-libs/linea-native-libs build;
Expand Down
2 changes: 0 additions & 2 deletions sdk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ FROM base AS builder

WORKDIR /usr/src/app

ARG GITHUB_API_ACCESS_TOKEN
ARG NATIVE_LIBS_RELEASE_TAG
ENV GITHUB_API_ACCESS_TOKEN=${GITHUB_API_ACCESS_TOKEN}
ENV NATIVE_LIBS_RELEASE_TAG=${NATIVE_LIBS_RELEASE_TAG}

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.json ./
Expand Down
34 changes: 15 additions & 19 deletions ts-libs/linea-native-libs/src/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ async function downloadAndParseJson(url: string, headers: Record<string, string>
return await response.json();
}

async function getReleaseAssetUrl(authToken: string, nativeLibReleaseTag: string): Promise<string> {
const urlStr = "https://api.github.com/repos/ConsenSys/zkevm-monorepo/releases";
async function getReleaseAssetUrl(nativeLibReleaseTag: string): Promise<string> {
const urlStr = "https://api.github.com/repos/Consensys/linea-monorepo/releases";

const json = await downloadAndParseJson(urlStr, { Authorization: `token ${authToken}` });
const json = await downloadAndParseJson(urlStr);
const release = json.find((release: any) => release.tag_name === nativeLibReleaseTag);

if (!release) {
Expand All @@ -38,15 +38,15 @@ async function getReleaseAssetUrl(authToken: string, nativeLibReleaseTag: string
}

const asset = release.assets.find((asset: any) => asset.name.includes(nativeLibReleaseTag));
return `https://${authToken}:@api.github.com/repos/Consensys/zkevm-monorepo/releases/assets/${asset.id}`;
return `https://api.github.com/repos/Consensys/linea-monorepo/releases/assets/${asset.id}`;
}

async function downloadFileUsingCurl(authToken: string, url: string, outputFilePath: string): Promise<string> {
async function downloadFileUsingCurl(url: string, outputFilePath: string): Promise<string> {
const outputDirectory = path.dirname(outputFilePath);

// Ensure the output directory exists
fs.mkdirSync(outputDirectory, { recursive: true });
const command = `curl -L -H 'Accept:application/octet-stream' -u ${authToken}: -o ${outputFilePath} ${url}`;
const command = `curl -L -H 'Accept:application/octet-stream' -o ${outputFilePath} ${url}`;

return new Promise((resolve, reject) => {
exec(command, (error: any, _: any, stderr: any) => {
Expand All @@ -67,12 +67,12 @@ const architectureResourceDirMapping: Record<string, string> = {
linux_x86_64: "linux-x64",
};

async function downloadReleaseAsset(authToken: string, nativeLibReleaseTag: string): Promise<string> {
const assetReleaseUrl = await getReleaseAssetUrl(authToken, nativeLibReleaseTag);
async function downloadReleaseAsset(nativeLibReleaseTag: string): Promise<string> {
const assetReleaseUrl = await getReleaseAssetUrl(nativeLibReleaseTag);
const fileName = `${nativeLibReleaseTag}.zip`;
const destPath = path.resolve("build", fileName);
console.log(`Downloading ${fileName} from ${assetReleaseUrl} to ${destPath}`);
return await downloadFileUsingCurl(authToken, assetReleaseUrl, destPath);
return await downloadFileUsingCurl(assetReleaseUrl, destPath);
}

function getBinaryResourceFolder(libFile: string): string {
Expand All @@ -91,12 +91,8 @@ function getBinaryResourceFileName(libFile: string, libName: string): string {
return `${libName}_${version}${extension}`;
}

async function downloadReleaseAndExtractToResources(
authToken: string,
nativeLibReleaseTag: string,
libName: string,
): Promise<void> {
const outputFile = await downloadReleaseAsset(authToken, nativeLibReleaseTag);
async function downloadReleaseAndExtractToResources(nativeLibReleaseTag: string, libName: string): Promise<void> {
const outputFile = await downloadReleaseAsset(nativeLibReleaseTag);

if (!fs.existsSync(outputFile)) {
throw new Error(`Output file ${outputFile} does not exist`);
Expand Down Expand Up @@ -127,13 +123,13 @@ async function downloadReleaseAndExtractToResources(
}
}

async function fetchLib(authToken: string, nativeLibReleaseTag: string, libName: string): Promise<void> {
await downloadReleaseAndExtractToResources(authToken, nativeLibReleaseTag, libName);
async function fetchLib(nativeLibReleaseTag: string, libName: string): Promise<void> {
await downloadReleaseAndExtractToResources(nativeLibReleaseTag, libName);
}

async function main() {
const { authToken, nativeLibReleaseTag } = getBuildConfig();
await fetchLib(authToken, nativeLibReleaseTag, "blob_compressor");
const { nativeLibReleaseTag } = getBuildConfig();
await fetchLib(nativeLibReleaseTag, "blob_compressor");
}

main()
Expand Down
8 changes: 0 additions & 8 deletions ts-libs/linea-native-libs/src/scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import { config } from "dotenv";
config();

type BuildConfig = {
authToken: string;
nativeLibReleaseTag: string;
};

export function getBuildConfig(): BuildConfig {
const authToken = process.env.GITHUB_API_ACCESS_TOKEN;

if (!authToken) {
throw new Error("GITHUB_API_ACCESS_TOKEN environment variable is not set");
}

const nativeLibReleaseTag = process.env.NATIVE_LIBS_RELEASE_TAG;

if (!nativeLibReleaseTag) {
throw new Error("NATIVE_LIBS_RELEASE_TAG environment variable is not set");
}

return {
authToken,
nativeLibReleaseTag,
};
}

0 comments on commit 81affa3

Please sign in to comment.