Skip to content

Commit

Permalink
Added summary to action and fixed exit error (#17)
Browse files Browse the repository at this point in the history
- Added a nice summary that is shown after every run.
- Made exiting of application conditional on the state.
- With the finally it would always exit as successful even if it failed.
  - Now it sets an error code when valid.
- Implemented action on itself.
  - Now it will run after each push.
  • Loading branch information
Bullrich authored Mar 18, 2024
1 parent 90c4e11 commit d1ee5d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/get-fellows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Mention fellows

on:
push:
branches:
- main

jobs:
mention-fellows:
runs-on: ubuntu-latest
steps:
- uses: paritytech/get-fellows-action@main
id: fellows
- name: Mention them
run: |
echo "The fellows are $FELLOWS"
env:
# the handles of the fellows separated by commas
FELLOWS: ${{ steps.fellows.outputs.github-handles }}"
40 changes: 31 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import { setFailed, setOutput } from "@actions/core";
import { setFailed, setOutput, summary } from "@actions/core";
import { SummaryTableRow } from "@actions/core/lib/summary";

import { FellowObject, fetchAllFellows } from "./fellows";
import { generateCoreLogger } from "./util";

const logger = generateCoreLogger();

const mapFellows = (fellows: FellowObject[]) => {
const mapFellows = async (fellows: FellowObject[]) => {
setOutput("fellows", JSON.stringify(fellows));
const githubHandles = fellows
.map((f) => f.githubHandle)
.filter((f) => !!f)
.map(({ githubHandle }) => githubHandle)
.filter((handle) => !!handle)
.join(",");
setOutput("github-handles", githubHandles);

const table: SummaryTableRow[] = [
[
{ header: true, data: "Rank" },
{ header: true, data: "GitHub Handle" },
{ header: true, data: "Address" },
],
];

for (const fellow of fellows.sort((old, { rank }) => rank - old.rank)) {
if (fellow.githubHandle) {
table.push([
fellow.rank.toString(),
`@${fellow.githubHandle}`,
fellow.address,
]);
}
}

await summary.addHeading("Fellows").addTable(table).write();

// TODO: Remove this once https://github.com/polkadot-api/polkadot-api/issues/327 is fixed
process.exit(0);
};

fetchAllFellows(logger)
.then(mapFellows)
.catch(setFailed)
.finally(() => {
logger.info("Shutting down application");
// TODO: Remove this once https://github.com/polkadot-api/polkadot-api/issues/327 is fixed
process.exit(0);
.catch((err) => {
setFailed(err as Error);
process.exit(1);
});

0 comments on commit d1ee5d0

Please sign in to comment.