Skip to content

Commit 4ca6892

Browse files
committed
fix Gravity for forks
1 parent dab9273 commit 4ca6892

2 files changed

Lines changed: 77 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: {}
8+
9+
jobs:
10+
build:
11+
name: Build Release Artifacts
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions-rust-lang/setup-rust-toolchain@v1
16+
- run: cargo publish --dry-run
17+
- run: cargo build -r
18+
- uses: actions/upload-artifact@v4
19+
with:
20+
name: artifacts
21+
path: |
22+
./target/release/gerust
23+
./target/package/gerust-*.crate

.github/workflows/gravity.yml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,67 @@
11
name: Gravity
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request: {}
4+
workflow_run:
5+
workflows: ["Build"]
6+
types:
7+
- completed
88

99
jobs:
10-
build:
10+
gravity:
1111
name: Run Gravity
1212
runs-on: ubuntu-latest
13-
if: github.repository == 'mainmatter/gerust'
13+
if: >
14+
github.event.workflow_run.conclusion == 'success'
1415
steps:
1516
- uses: actions/checkout@v4
1617
- uses: pnpm/action-setup@v4
1718
with:
1819
version: 10
19-
- uses: actions-rust-lang/setup-rust-toolchain@v1
20-
- run: cargo publish --dry-run
21-
- run: cargo build -r
22-
- run: pnpm dlx @gravityci/cli "./target/release/gerust" "./target/package/gerust-*.crate" # keep track of the sizes of both the .crate file as well as the binary
20+
- name: 'Download artifact'
21+
uses: actions/github-script@v6
22+
with:
23+
script: |
24+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
run_id: context.payload.workflow_run.id,
28+
});
29+
30+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
31+
return artifact.name == "artifacts"
32+
})[0];
33+
34+
let download = await github.rest.actions.downloadArtifact({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
artifact_id: matchArtifact.id,
38+
archive_format: 'zip',
39+
});
40+
41+
let fs = require('fs');
42+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifacts.zip`, Buffer.from(download.data));
43+
- name: 'Unzip artifact'
44+
run: unzip artifacts.zip -d artifacts
45+
- name: 'Get PR context'
46+
if: >
47+
github.event.workflow_run.event == 'pull_request'
48+
id: pr-context
49+
env:
50+
GH_TOKEN: ${{ github.token }}
51+
PR_TARGET_REPO: ${{ github.repository }}
52+
PR_BRANCH: |-
53+
${{
54+
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
55+
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
56+
|| github.event.workflow_run.head_branch
57+
}}
58+
run: |
59+
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
60+
--json 'number,headRefOid' \
61+
--jq '"number=\(.number)\nhead-sha=\(.headRefOid)"' \
62+
>> $GITHUB_OUTPUT
63+
- run: pnpm dlx @gravityci/cli "artifacts" # keep track of the sizes of both the .crate file as well as the binary
2364
env:
24-
GRAVITY_TOKEN: ${{ secrets.GRAVITY_TOKEN }}
65+
GRAVITY_SHA: ${{ github.event.workflow_run.head_sha }}
66+
GRAVITY_PR_ID: ${{ github.event.workflow_run.event == 'pull_request' && steps.pr-context.outputs.number || '' }}
67+
GRAVITY_TOKEN: ${{ secrets.GRAVITY_TOKEN }}

0 commit comments

Comments
 (0)