Skip to content

Commit

Permalink
v1.0.2 - Add version as output
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Jan 16, 2023
1 parent 50f93b3 commit a5e8f22
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
default: packages.json
description: 'File the package information is written to'

outputs:
version:
description: Version string of the package

runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
15 changes: 12 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dl-package-info",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"description": "Package for downloading package information off of Github.",
"main": "lib/main.js",
Expand Down
18 changes: 15 additions & 3 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const query = `query getPackageInfo($org: String!, $repo: String!, $filter: [Str
packages(first: 1, names: $filter) {
nodes {
latestVersion {
version
files(first: 25) {
nodes {
name
Expand All @@ -21,6 +22,11 @@ const query = `query getPackageInfo($org: String!, $repo: String!, $filter: [Str
}
}`;

export interface GHPackageInfo {
version: string;
files: GHPackage[];
}

export interface GHPackage {
name: string;
size: bigint;
Expand All @@ -30,7 +36,7 @@ export interface GHPackage {
}

export class GithubPackages {
public static async getPackageInfo(org: string, repo: string, groups: string[]): Promise<GHPackage[]> {
public static async getPackageInfo(org: string, repo: string, groups: string[]): Promise<GHPackageInfo> {
const getPackageInfo = await graphql<any>(query, {
org: org,
repo: repo,
Expand All @@ -40,7 +46,13 @@ export class GithubPackages {
}
});

let pkg = getPackageInfo.repository.packages.nodes[0].latestVersion.files.nodes as GHPackage[];
return pkg;
let latestVersion = getPackageInfo.repository.packages.nodes[0].latestVersion;
let version = latestVersion.version;
let pkg = latestVersion.files.nodes as GHPackage[];

return {
version: version,
files: pkg
};
}
}
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInput, debug, setFailed } from '@actions/core'
import { getInput, setOutput, debug, setFailed } from '@actions/core'
import { GithubPackages } from "./github";
import { writeFile } from "fs/promises";

Expand All @@ -18,7 +18,9 @@ async function run() {
matchFileFilters.push(new RegExp(filter));
}

let matchedFiles = await GithubPackages.getPackageInfo(owner, repo, [group]);
let pkg = await GithubPackages.getPackageInfo(owner, repo, [group]);
let latestVersion = pkg.version;
let matchedFiles = pkg.files;
if (matchFileFilters.length > 0) {
debug("Pre-filter count: " + matchedFiles.length);
matchedFiles = matchedFiles.filter(file => {
Expand All @@ -33,6 +35,8 @@ async function run() {
const actualOut = outFile ?? "packages.json";
debug("Writing output file: " + actualOut)
await writeFile(actualOut, JSON.stringify(matchedFiles));

setOutput("version", latestVersion);
}

catch (err) {
Expand Down

0 comments on commit a5e8f22

Please sign in to comment.