Skip to content

Commit

Permalink
fork_prs
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Sep 14, 2023
1 parent c1d26ef commit b4e8c98
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
52 changes: 26 additions & 26 deletions services/cli/src/bencher/sub/project/run/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ pub enum GitHubError {
BadEventPath(String, std::io::Error),
#[error("Failed to parse GitHub Action event ({0}): {1}")]
BadEvent(String, serde_json::Error),
#[error("GitHub Action event ({0}) PR number is missing")]
NoPRNumber(String),
#[error("GitHub Action event ({0}) PR number is invalid")]
BadPRNumber(String),
#[error("GitHub Action event workflow run is missing")]
NoWorkFlowRun,
#[error("GitHub Action event workflow run pull requests is missing")]
NoPullRequests,
#[error("GitHub Action event workflow run pull requests is empty")]
EmptyPullRequests,
#[error("GitHub Action event repository is missing")]
NoRepository,
#[error("GitHub Action event repository full name is missing")]
NoFullName,
#[error("GitHub Action event repository full name is invalid")]
BadFullName,
#[error("GitHub Action event ({1}) PR number is missing: {0}")]
NoPRNumber(String, String),
#[error("GitHub Action event ({1}) PR number is invalid: {0}")]
BadPRNumber(String, String),
#[error("GitHub Action event workflow run is missing: {0}")]
NoWorkFlowRun(String),
#[error("GitHub Action event workflow run pull requests is missing: {0}")]
NoPullRequests(String),
#[error("GitHub Action event workflow run pull requests is empty: {0}")]
EmptyPullRequests(String),
#[error("GitHub Action event repository is missing: {0}")]
NoRepository(String),
#[error("GitHub Action event repository full name is missing: {0}")]
NoFullName(String),
#[error("GitHub Action event repository full name is invalid: {0}")]
BadFullName(String),
#[error("GitHub Action event repository full name is not of the form `owner/repo`: ({0})")]
InvalidFullName(String),
#[error("Failed to authenticate as GitHub Action: {0}")]
Expand Down Expand Up @@ -145,24 +145,24 @@ impl GitHubActions {
// https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request
event
.get(NUMBER_KEY)
.ok_or_else(|| GitHubError::NoPRNumber(event_name.into()))?
.ok_or_else(|| GitHubError::NoPRNumber(event_str.clone(), event_name.into()))?
.as_u64()
.ok_or_else(|| GitHubError::BadPRNumber(event_name.into()))?
.ok_or_else(|| GitHubError::BadPRNumber(event_str.clone(), event_name.into()))?
},
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
Some(event_name @ "workflow_run") => {
// https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_run
event
.get(event_name)
.ok_or(GitHubError::NoWorkFlowRun)?
.ok_or_else(|| GitHubError::NoWorkFlowRun(event_str.clone()))?
.get("pull_requests")
.ok_or(GitHubError::NoPullRequests)?
.ok_or_else(|| GitHubError::NoPullRequests(event_str.clone()))?
.get(0)
.ok_or(GitHubError::EmptyPullRequests)?
.ok_or_else(|| GitHubError::EmptyPullRequests(event_str.clone()))?
.get(NUMBER_KEY)
.ok_or_else(|| GitHubError::NoPRNumber(event_name.into()))?
.ok_or_else(|| GitHubError::NoPRNumber(event_str.clone(), event_name.into()))?
.as_u64()
.ok_or_else(|| GitHubError::BadPRNumber(event_name.into()))?
.ok_or_else(|| GitHubError::BadPRNumber(event_str.clone(), event_name.into()))?
},
_ => {
cli_println!(
Expand All @@ -177,11 +177,11 @@ impl GitHubActions {
// https://docs.github.com/en/rest/repos/repos#get-a-repository
let full_name = event
.get("repository")
.ok_or(GitHubError::NoRepository)?
.ok_or_else(|| GitHubError::NoRepository(event_str.clone()))?
.get("full_name")
.ok_or(GitHubError::NoFullName)?
.ok_or_else(|| GitHubError::NoFullName(event_str.clone()))?
.as_str()
.ok_or(GitHubError::BadFullName)?;
.ok_or_else(|| GitHubError::BadFullName(event_str.clone()))?;
// The owner and repository name. For example, octocat/Hello-World.
let (owner, repo) = if let Some((owner, repo)) = full_name.split_once('/') {
(owner.to_owned(), repo.to_owned())
Expand Down
14 changes: 10 additions & 4 deletions services/console/src/content/how_to/github-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ jobs:
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }}
BENCHER_ADAPTER: json
BENCHER_TESTBED: ubuntu-latest
BENCHMARK_RESULTS: benchmark_results.txt
steps:
- name: Download Benchmark Results
uses: actions/github-script@v6
Expand All @@ -181,22 +182,27 @@ jobs:
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "benchmark_results"
return artifact.name == process.env.BENCHMARK_RESULTS
})[0];
if (!matchArtifact) {
core.setFailed(
`Failed to find benchmark results artifact: ${process.env.BENCHMARK_RESULTS}`
);
}
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/benchmark_results.zip`, Buffer.from(download.data));
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/results.zip`, Buffer.from(download.data));
- name: Unzip Benchmark Results
run: unzip benchmark_results.zip
run: unzip results.zip
- uses: bencherdev/bencher@main
- name: Track Benchmarks with Bencher
run: |
cat benchmark_results.txt | bencher run \\
cat $BENCHMARK_RESULTS | bencher run \\
--if-branch "${{ github.event.workflow_run.pull_requests[0]?.head.ref }}" \\
--else-if-branch "${{ github.event.workflow_run.pull_requests[0]?.base.ref }}" \\
--else-if-branch main \\
Expand Down
7 changes: 6 additions & 1 deletion services/console/src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../styles/styles.scss";
import Navbar from "../components/site/navbar/Navbar";
import Footer from "../components/site/Footer";
import { BENCHER_TITLE, BENCHER_DESCRIPTION } from "../util/resource";
import { BENCHER_LOGO_URL } from "../util/ext";
// import { ViewTransitions } from "astro:transitions";
interface Props {
Expand Down Expand Up @@ -37,7 +38,11 @@ const { title, description } = Astro.props;
basic: {
title: title,
type: "website",
image: "https://bencher.dev/favicon.svg",
image: BENCHER_LOGO_URL,
},
optional: {
siteName: "Bencher",
description: description ?? BENCHER_DESCRIPTION,
}
}}
twitter={{
Expand Down

0 comments on commit b4e8c98

Please sign in to comment.