Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .junie/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Aliases:
Ignore the following properties:

- `directory`
- `readme`
- `repository.owner`
- `repository.repo`

Expand All @@ -20,3 +21,4 @@ Steps:
2. Study its dependencies.
3. Memorize the overall relationship scheme of these interfaces.
4. Update the JSON schema in the `resources/schema.json` file in accordance with the new requirements.
5. Do not add the `default` parameter to the schema root.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ jobs:
# Required: true
token: ${{ secrets.GITHUB_TOKEN }}

# Path to the settings file
# Path to the settings file
#
# By default, .github/preview-updater.yml
#
# Required: false
config: ''

# Specifies the path to the README file.
#
# By default, README.md
#
# Required: false
readme: ''
```

The action is setting the following outputs:
Expand Down Expand Up @@ -82,8 +89,6 @@ All fields are optional—omitted ones fall back to defaults.
```yaml
# $schema: https://raw.githubusercontent.com/TheDragonCode/github-preview-updater/refs/heads/main/resources/schema.json

path: README.md # Target file to update

package:
# Declares the use of the package manager.
# It is a regular string that will be substituted into the URL address.
Expand Down Expand Up @@ -169,7 +174,7 @@ Ultimately, the image link will look like this:

## FAQ

> 💥 Preview Updater failed with error: Error when creating pull request from preview/banner-***: GitHub Actions is not permitted to create or approve pull requests
> 💥 Preview Updater failed with error: Error when creating a pull request from preview/banner-***: GitHub Actions is not permitted to create or approve pull requests

Enable the "Allow GitHub Actions to create and approve pull requests" option in project settings.

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ inputs:
description: Path to the preview configuration YAML file.
default: '.github/preview-updater.yml'
required: false

readme:
description: Specifies the path to the README file.
default: 'README.md'
required: false
5 changes: 0 additions & 5 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
"type": "object",
"additionalProperties": false,
"properties": {
"readme": {
"type": "string",
"description": "Target README file where the banner will be inserted",
"default": "README.md"
},
"repository": {
"type": "object",
"additionalProperties": false,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Config } from "../types/config";
import type { Image } from "../types/image";
import type { Package } from "../types/package";
import type { Author, Commit, PullRequest } from "../types/repository";
import { README_PATH } from "../utils/inputs";

export const defaultPackage: Package = {
manager: "auto",
Expand Down Expand Up @@ -39,7 +40,7 @@ export const defaultPullRequest: PullRequest = {
};

export const defaultConfig: Config = {
readme: "README.md",
readme: README_PATH.defaultValue,

package: defaultPackage,
image: defaultImage,
Expand Down
16 changes: 6 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import { readConfig } from "./utils/config";
import type { LockFile } from "./types/lockFile";
import type { Data } from "./types/data";
import type { Repository as Credentials } from "./types/repository";
import {
defaultConfig,
defaultPackage,
defaultPullRequest,
} from "./libs/defaults";
import { defaultPackage, defaultPullRequest } from "./libs/defaults";
import type { GitHub } from "@actions/github/lib/utils";

const previewUpdater = async () => {
// Inputs
const { token, configPath } = parse();
const { token, configPath, readmePath } = parse();

// Credentials
const credentials: Credentials = {
Expand Down Expand Up @@ -53,7 +49,7 @@ const previewUpdater = async () => {
// Read names
const packageLock: LockFile = getPackageManager(config);

config.readme ||= defaultConfig.readme || "README.md";
config.readme = readmePath;

config.package ||= defaultPackage;
config.data ||= <Data>{};
Expand All @@ -71,8 +67,8 @@ const previewUpdater = async () => {
await repo.authenticate();

// Read file
const content = readFile(config, config.readme);
const preview = setPreview(content, config, packageLock);
const content: string = readFile(config, config.readme);
const preview: string = setPreview(content, config, packageLock);

if (content === preview) {
info(`File "${config.readme}" is up to date`);
Expand All @@ -81,7 +77,7 @@ const previewUpdater = async () => {
}

// Checkout branch
const branchExists = await repo.branchExists();
const branchExists: boolean = await repo.branchExists();
info(
`Checkout ${branchExists ? "existing" : "new"} branch named "${repo.branchName()}"`,
);
Expand Down
9 changes: 7 additions & 2 deletions src/utils/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ import { getInput } from "@actions/core";

export const TOKEN = {
name: "token",
env: "INPUT_TOKEN",
};

export const CONFIG_PATH = {
name: "config",
env: "INPUT_CONFIG_PATH",
defaultValue: ".github/preview-updater.yml",
};

export const README_PATH = {
name: "readme",
defaultValue: "README.md",
};

export const parse = () => {
const token = getInput(TOKEN.name, { required: true });
const configPath = getInput(CONFIG_PATH.name) || CONFIG_PATH.defaultValue;
const readmePath = getInput(README_PATH.name) || README_PATH.defaultValue;

return {
token,
configPath,
readmePath,
};
};
2 changes: 1 addition & 1 deletion src/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class Repository {
});
} catch (error) {
// @ts-expect-error
error.message = `Error when creating pull request from ${this.branchName()}: ${error.message}`;
error.message = `Error when creating a pull request from ${this.branchName()}: ${error.message}`;

throw error;
}
Expand Down