Skip to content

Commit

Permalink
feat(ci): early return when no artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Mar 14, 2023
1 parent f1d0ac9 commit 3a10173
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ export const checkLayouts = async (
address,
provider,
checkRemovals,
strictTypes,
}: { address?: string; provider?: Provider; checkRemovals?: boolean; strictTypes?: boolean } = {}
}: { address?: string; provider?: Provider; checkRemovals?: boolean } = {}
): Promise<StorageLayoutDiff[]> => {
const diffs: StorageLayoutDiff[] = [];
const added: StorageLayoutDiffAdded[] = [];
Expand Down Expand Up @@ -272,17 +271,18 @@ export const checkLayouts = async (
return _uniqWith(
_sortBy(diffs, ["location.slot", "location.offset"]), // make sure it's ordered by storage byte order
({ location: location1, ...diff1 }, { location: location2, ...diff2 }) => _isEqual(diff1, diff2) // only keep first byte diff of a variable, which corresponds to the start byte
).concat(address && provider ? await checkAddedStorageSlots(added, address, provider) : []);
).concat(await checkAddedStorageSlots(added, address, provider));
};

const checkAddedStorageSlots = async (
added: StorageLayoutDiffAdded[],
address: string,
provider: Provider
address?: string,
provider?: Provider
): Promise<StorageLayoutDiffAddedNonZeroSlot[]> => {
const storage: { [slot: string]: string } = {};
const diffs: StorageLayoutDiffAddedNonZeroSlot[] = [];
if (!address || !provider) return [];

const storage: { [slot: string]: string } = {};
for (const diff of _sortBy(added, ["location.slot", "location.offset"])) {
const slot = diff.location.slot.toString();

Expand Down
7 changes: 2 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const repository = owner + "/" + repo;
const provider = rpcUrl ? getDefaultProvider(rpcUrl) : undefined;

let srcContent: string;
let refCommitHash: string | undefined;
let refCommitHash: string | undefined = undefined;

async function run() {
core.startGroup(`Generate storage layout of contract "${contract}" using foundry forge`);
Expand Down Expand Up @@ -118,16 +118,13 @@ async function run() {
srcContent = zip.readAsText(entry);
}
core.endGroup();
} else core.error(`No workflow run found with an artifact named "${baseReport}"`);
} else return core.error(`No workflow run found with an artifact named "${baseReport}"`);
} catch (error: any) {
return core.setFailed(error.message);
}
}

try {
core.startGroup("Load storage layout reports");
srcContent ??= cmpContent; // if no source storage layout report were loaded, defaults to the current storage layout report

core.info(`Mapping reference storage layout report`);
const srcLayout = parseLayout(srcContent);
core.endGroup();
Expand Down

0 comments on commit 3a10173

Please sign in to comment.