|
1 | 1 | import { getInput, setFailed, debug, setOutput } from "@actions/core";
|
2 | 2 | import { context, getOctokit } from "@actions/github";
|
3 | 3 | import { load as loadYaml } from "js-yaml";
|
| 4 | +import fs from "fs"; |
4 | 5 |
|
5 | 6 | type GitHubClient = ReturnType<typeof getOctokit>["rest"];
|
6 | 7 |
|
@@ -151,21 +152,31 @@ function regexifyConfigPath(configPath: string, version: string) {
|
151 | 152 | /** Load the configuration file */
|
152 | 153 | async function loadConfig(client: GitHubClient, configPath: string) {
|
153 | 154 | try {
|
154 |
| - const { data } = await client.repos.getContent({ |
155 |
| - owner: context.repo.owner, |
156 |
| - repo: context.repo.repo, |
157 |
| - ref: context.sha, |
158 |
| - path: configPath, |
159 |
| - }); |
| 155 | + let configContent: string |
160 | 156 |
|
161 |
| - if (!("content" in data)) { |
162 |
| - throw new TypeError( |
163 |
| - "The configuration path provided is not a valid file. Exiting" |
164 |
| - ); |
165 |
| - } |
| 157 | + if (fs.existsSync(configPath)) { |
| 158 | + console.log(`Configuration file (path: ${configPath}) exists locally, loading from file`); |
166 | 159 |
|
167 |
| - const configContent = Buffer.from(data.content, "base64").toString("utf8"); |
| 160 | + configContent = fs.readFileSync(configPath, { encoding: "utf8" }); |
| 161 | + } else { |
| 162 | + console.log(`Configuration file (path: ${configPath}) does not exist locally, fetching via the API`); |
168 | 163 |
|
| 164 | + const { data } = await client.repos.getContent({ |
| 165 | + owner: context.repo.owner, |
| 166 | + repo: context.repo.repo, |
| 167 | + ref: context.sha, |
| 168 | + path: configPath, |
| 169 | + }); |
| 170 | + |
| 171 | + if (!("content" in data)) { |
| 172 | + throw new TypeError( |
| 173 | + "The configuration path provided is not a valid file. Exiting" |
| 174 | + ); |
| 175 | + } |
| 176 | + |
| 177 | + configContent = Buffer.from(data.content, "base64").toString("utf8"); |
| 178 | + } |
| 179 | + |
169 | 180 | // loads (hopefully) a `{[label:string]: string | string[]}`, but is `any`:
|
170 | 181 | const configObject = loadYaml(configContent);
|
171 | 182 |
|
|
0 commit comments