Skip to content

Commit

Permalink
Merge pull request #553 from arlyon/public-api
Browse files Browse the repository at this point in the history
Public api
  • Loading branch information
arlyon authored Sep 24, 2024
2 parents 9705163 + 0442cbc commit bf68a94
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/async-stripe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,37 @@ jobs:
# with:
# name: code-coverage-report
# path: lcov.info

generate-public-api:
continue-on-error: true
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Install cargo-public-api
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-public-api
- name: Save PR number
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const util = require('util');
fs.mkdirSync("./public-api", { recursive: true });
const payload = context.payload;
const number = (payload.issue || payload.pull_request || payload).number;
const text = number === undefined ? "" : String(number);
core.info("Pr number is " + number + ", writing \"" + text + "\"");
fs.writeFileSync("./public-api/pr_number", text);
- name: Compare with latest version published on crates.io
run: cargo public-api diff latest --features runtime-tokio-hyper >> "public-api/diff"
- uses: actions/upload-artifact@v3
with:
name: public-api
path: public-api/
84 changes: 84 additions & 0 deletions .github/workflows/public-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Cargo-public-api comment

on:
workflow_run:
workflows: [Tests]
types:
- completed

# taken from https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
id: da
uses: actions/github-script@v6
with:
script: |
if (context.payload.workflow_run === undefined) {
core.setFailed("No workflow run found");
}
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const theArtifact = allArtifacts.data.artifacts.find((artifact) => {
return artifact.name == "public-api"
});
if (theArtifact !== undefined) {
core.info("Found pr-number artifact id: " + theArtifact.id);
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: theArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/public_api.zip`, Buffer.from(download.data));
} else {
core.setFailed("Artifact public-api was not found");
}
- name: 'Unzip artifact'
run: unzip public_api.zip

- name: 'Read artifact'
id: ra
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
let issue_number_text = fs.readFileSync('./pr_number', 'uft8');
core.info("Found pr number \"" + issue_number_text + "\"");
core.setOutput("pr-number", issue_number_text === "" ? "" : Number(issue_number_text));
let diff = fs.readFileSync('./diff', 'uft8');
core.setOutput("diff", diff);
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ steps.ra.outputs.pr-number }}
comment-author: "github-actions[bot]"
body-includes: Removed items from the public API

- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.ra.outputs.pr-number }}
body: |
${{ steps.ra.outputs.diff }}
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
${{ steps.ra.outputs.diff }}

0 comments on commit bf68a94

Please sign in to comment.