-
Notifications
You must be signed in to change notification settings - Fork 2
manual song post creation #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jtzero
wants to merge
1
commit into
main
Choose a base branch
from
manual-post-creation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| name: Create Songbook Post | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| filename: | ||
| description: "Filename / Slug for the post (e.g. bukayo-saka)" | ||
| required: true | ||
| type: string | ||
| title: | ||
| description: "Post Title (Optional if imageAlt provided)" | ||
| required: false | ||
| type: string | ||
| date: | ||
| description: "Post Date in YYYY-MM-DD format (Optional)" | ||
| required: false | ||
| type: string | ||
| image: | ||
| description: "Image URL (Required, e.g. https://example.com/image.jpg)" | ||
| required: true | ||
| type: string | ||
| imageAlt: | ||
| description: "Image Alt text (Optional if title provided)" | ||
| required: false | ||
| type: string | ||
| imageDimensions: | ||
| description: "Image dimensions WxH (Required, e.g. 735x990)" | ||
| required: true | ||
| type: string | ||
| imagePlacement: | ||
| description: 'Image placement (Required, e.g. header, body, or JSON: {"all":"header","md":"body"})' | ||
| required: true | ||
| default: "header" | ||
| type: string | ||
| imageLink: | ||
| description: "Image link URL (Optional)" | ||
| required: false | ||
| type: string | ||
| orientation: | ||
| description: "Image orientation (Optional, e.g. portrait, landscape, square, banner)" | ||
| required: false | ||
| type: string | ||
| metaTitle: | ||
| description: "Meta Title for SEO (Optional)" | ||
| required: false | ||
| type: string | ||
| additionalStyling: | ||
| description: "Additional CSS styling class (Optional)" | ||
| required: false | ||
| type: string | ||
| content: | ||
| description: "Post Markdown / Song Lyrics content (Optional)" | ||
| required: false | ||
| type: string | ||
| imageFileName: | ||
| description: "Filename to save the downloaded image in public/ (e.g. my-image.jpg)" | ||
| required: true | ||
| type: string | ||
| branch: | ||
| description: "The branch to run on" | ||
| required: true | ||
| default: "main" | ||
| type: string | ||
|
|
||
| jobs: | ||
| create-songbook-post: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ssh-key: ${{ secrets.DATA_PIPELINE_PR_AUTOMATION_KEY }} | ||
| ref: ${{ inputs.branch }} | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: "npm" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Download image | ||
| run: | | ||
| mkdir -p public | ||
| IMAGE_PATH="public/${{ inputs.imageFileName }}" | ||
| mkdir -p "$(dirname "$IMAGE_PATH")" | ||
| curl -L -o "$IMAGE_PATH" ${{ inputs.image }} | ||
|
|
||
| - name: Create Songbook Post | ||
| env: | ||
| INPUT_FILENAME: ${{ inputs.filename }} | ||
| INPUT_TITLE: ${{ inputs.title }} | ||
| INPUT_DATE: ${{ inputs.date }} | ||
| INPUT_IMAGE: /${{ inputs.imageFileName }} | ||
| INPUT_IMAGE_ALT: ${{ inputs.imageAlt }} | ||
| INPUT_IMAGE_DIMENSIONS: ${{ inputs.imageDimensions }} | ||
| INPUT_IMAGE_PLACEMENT: ${{ inputs.imagePlacement }} | ||
| INPUT_IMAGE_LINK: ${{ inputs.imageLink }} | ||
| INPUT_ORIENTATION: ${{ inputs.orientation }} | ||
| INPUT_META_TITLE: ${{ inputs.metaTitle }} | ||
| INPUT_ADDITIONAL_STYLING: ${{ inputs.additionalStyling }} | ||
| INPUT_CONTENT: ${{ inputs.content }} | ||
| run: npm run create-songbook-post | ||
|
|
||
| - name: Format generated post | ||
| run: npm run format | ||
|
|
||
| - name: Run unit tests | ||
| run: npm run test:unit | ||
|
|
||
| - name: Log git status | ||
| run: git status | ||
|
|
||
| - name: Create Pull Request | ||
| id: cpr | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| commit-message: "feat(songbook): add songbook post ${{ inputs.filename }}" | ||
| branch: "songbook-post-${{ inputs.filename }}" | ||
| base: "main" | ||
| add-paths: | | ||
| src/content/posts/* | ||
| public/${{ inputs.imageFileName }} | ||
| title: "New Songbook Post: ${{ inputs.title || inputs.filename }}" | ||
| body: | | ||
| This is an automated pull request to create a new songbook post using `imagePost` schema inputs. | ||
| labels: | | ||
| songbook-post | ||
|
|
||
| - name: Enable Pull Request Automerge | ||
| if: steps.cpr.outputs.pull-request-number != '' | ||
| run: | | ||
| gh pr merge --rebase --auto "${{ steps.cpr.outputs.pull-request-number }}" | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { | ||
| createSongbookPostFile, | ||
| type SongbookPostInput, | ||
| } from "@/lib/createSongbookPost"; | ||
|
|
||
| const input: SongbookPostInput = { | ||
| filename: process.env.INPUT_FILENAME || process.argv[2] || "", | ||
| title: process.env.INPUT_TITLE || undefined, | ||
| date: process.env.INPUT_DATE || undefined, | ||
| image: process.env.INPUT_IMAGE || process.argv[3] || "", | ||
| imageAlt: process.env.INPUT_IMAGE_ALT || undefined, | ||
| imageDimensions: process.env.INPUT_IMAGE_DIMENSIONS || process.argv[4] || "", | ||
| imagePlacement: | ||
| process.env.INPUT_IMAGE_PLACEMENT || process.argv[5] || "header", | ||
| imageLink: process.env.INPUT_IMAGE_LINK || undefined, | ||
| orientation: process.env.INPUT_ORIENTATION || undefined, | ||
| metaTitle: process.env.INPUT_META_TITLE || undefined, | ||
| additionalStyling: process.env.INPUT_ADDITIONAL_STYLING || undefined, | ||
| content: process.env.INPUT_CONTENT || undefined, | ||
| }; | ||
|
|
||
| if (!input.filename) { | ||
| console.error("Error: 'filename' input is required."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!input.image) { | ||
| console.error("Error: 'image' input is required."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!input.imageDimensions) { | ||
| console.error("Error: 'imageDimensions' input is required."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| try { | ||
| const result = createSongbookPostFile(input); | ||
| console.log(`Successfully created songbook post at: ${result.filePath}`); | ||
| } catch (error) { | ||
| console.error("Error creating songbook post:", error); | ||
| process.exit(1); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import os from "os"; | ||
| import { describe, expect, test } from "vitest"; | ||
| import { | ||
| generateSongbookPostMarkdown, | ||
| createSongbookPostFile, | ||
| parseImagePlacement, | ||
| } from "./createSongbookPost"; | ||
| import { postSchema } from "@/content.types"; | ||
|
|
||
| describe("createSongbookPost", () => { | ||
| describe("parseImagePlacement", () => { | ||
| test("parses plain string placement", () => { | ||
| expect(parseImagePlacement("header")).toBe("header"); | ||
| expect(parseImagePlacement("body")).toBe("body"); | ||
| }); | ||
|
|
||
| test("parses valid JSON object placement", () => { | ||
| const result = parseImagePlacement('{"all":"header","md":"body"}'); | ||
| expect(result).toEqual({ all: "header", md: "body" }); | ||
| }); | ||
|
|
||
| test("falls back to raw string when JSON is invalid", () => { | ||
| const result = parseImagePlacement("{invalid json}"); | ||
| expect(result).toBe("{invalid json}"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("generateSongbookPostMarkdown", () => { | ||
| test("generates markdown compliant with imagePost schema", () => { | ||
| const markdown = generateSongbookPostMarkdown({ | ||
| filename: "saka-chant", | ||
| title: "Bukayo Saka", | ||
| image: "/images/saka.jpg", | ||
| imageDimensions: "735x990", | ||
| imagePlacement: "header", | ||
| orientation: "portrait", | ||
| content: "We've got Bukayo Saka...", | ||
| }); | ||
|
|
||
| expect(markdown).toContain('title: "Bukayo Saka"'); | ||
| expect(markdown).toContain('image: "/images/saka.jpg"'); | ||
| expect(markdown).toContain('imageDimensions: "735x990"'); | ||
| expect(markdown).toContain("imagePlacement: header"); | ||
| expect(markdown).toContain("We've got Bukayo Saka..."); | ||
| }); | ||
|
|
||
| test("supports imagePlacement as responsive JSON object", () => { | ||
| const markdown = generateSongbookPostMarkdown({ | ||
| filename: "rice-chant", | ||
| title: "Declan Rice", | ||
| image: "/images/rice.jpg", | ||
| imageDimensions: "1242x828", | ||
| imagePlacement: '{"all":"header","md":"body"}', | ||
| imageAlt: "Declan Rice celebrating", | ||
| content: "Declan Rice...", | ||
| }); | ||
|
|
||
| expect(markdown).toContain("imagePlacement:"); | ||
| expect(markdown).toContain(" all: header"); | ||
| expect(markdown).toContain(" md: body"); | ||
| expect(markdown).toContain('imageAlt: "Declan Rice celebrating"'); | ||
| }); | ||
|
|
||
| test("throws error if inputs fail imagePost schema validation", () => { | ||
| expect(() => { | ||
| generateSongbookPostMarkdown({ | ||
| filename: "invalid-post", | ||
| image: "/images/test.jpg", | ||
| imageDimensions: "100x100", | ||
| imagePlacement: "header", | ||
| // Missing both title and imageAlt | ||
| }); | ||
| }).toThrowError(/Validation failed for imagePost schema/); | ||
| }); | ||
| }); | ||
|
|
||
| describe("createSongbookPostFile", () => { | ||
| test("creates songbook post file in target directory", () => { | ||
| const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "songbook-test-")); | ||
| try { | ||
| const result = createSongbookPostFile( | ||
| { | ||
| filename: "saliba-chant", | ||
| title: "William Saliba", | ||
| image: "/images/saliba.jpg", | ||
| imageDimensions: "500x500", | ||
| imagePlacement: "body", | ||
| content: "Te-quila!", | ||
| }, | ||
| tmpDir, | ||
| ); | ||
|
|
||
| const expectedPath = path.join( | ||
| tmpDir, | ||
| "src", | ||
| "content", | ||
| "posts", | ||
| "saliba-chant.md", | ||
| ); | ||
| expect(result.filePath).toBe(expectedPath); | ||
| expect(fs.existsSync(expectedPath)).toBe(true); | ||
|
|
||
| const writtenContent = fs.readFileSync(expectedPath, "utf-8"); | ||
| expect(writtenContent).toContain('title: "William Saliba"'); | ||
| expect(writtenContent).toContain("Te-quila!"); | ||
| } finally { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: jtzero/cle-gunners
Length of output: 307
🏁 Script executed:
Repository: jtzero/cle-gunners
Length of output: 5423
🌐 Web query:
GitHub Actions workflow_dispatch user permissions write access required💡 Result:
To manually trigger a GitHub Actions workflow using the workflow_dispatch event, write access to the repository is required [1][2][3]. Key details regarding permissions and requirements: 1. Repository Access: Users or service accounts (via tokens) must have write access to the repository to trigger a workflow manually via the GitHub UI, GitHub CLI, or REST API [1][4][3]. 2. Workflow Location: The workflow file must exist on the repository's default branch for the workflow_dispatch trigger to be active and recognized by GitHub [1][5][3]. 3. Authentication Scopes: When using API tokens (Personal Access Tokens or OAuth tokens), the required permissions typically involve repository write access (often represented by the repo scope for classic tokens) or specific fine-grained permissions such as actions:write [6][4][7]. 4. UI Visibility: If a user does not have write access, they will not see the Run workflow button in the GitHub Actions tab, even if the workflow is properly configured [1][2]. In summary, write access is a fundamental requirement for manually invoking workflows configured with workflow_dispatch, as it ensures only authorized users can initiate these actions [1][2][3].
Citations:
🌐 Web query:
npm install runs lifecycle scripts install lifecycle documentation💡 Result:
In npm, lifecycle scripts are automated hooks defined in the scripts property of a package.json file that execute at specific stages of package installation and management [1][2][3]. As of July 2026, with the release of npm v12, significant security changes have been implemented regarding these scripts [4]. Lifecycle Scripts and npm install When running npm install, the following lifecycle scripts are standard: - preinstall: Executes before the package is installed [3][4]. - install: Executes after the package is installed [3][4]. - postinstall: Executes after the package is installed [3][4]. Important Security Change (npm v12+) Prior to npm v12, these scripts executed automatically by default, posing significant supply chain security risks [5][6][4]. Starting with npm v12 (released July 2026), all dependency install scripts are disabled by default [4]. Furthermore, this protection now extends to the implicit node-gyp rebuild process (triggered by binding.gyp files), which previously acted as a "Phantom Gyp" bypass for security controls [4]. Packages that require these scripts must now be explicitly allowlisted in the project's npm configuration [7][4]. Execution Order During an npm install command, the lifecycle scripts for the project and its dependencies typically follow this general sequence [3]: 1. preinstall 2. install 3. postinstall 4. prepublish 5. preprepare 6. prepare 7. postprepare Note that recent updates have refined the execution of root-level preinstall scripts to ensure they run before dependency resolution (reify) begins, addressing long-standing issues where root scripts could not effectively gate the installation process [8]. Management and Environment Variables - Environment Variable: The npm_lifecycle_event environment variable is set during execution, allowing a single script to detect which lifecycle stage is currently active [1][9][2]. - Best Practices: Users should avoid relying on automatic script execution for critical build steps and should instead use explicit, controlled build processes [5][10]. Reviewing the hasInstallScript flag in package-lock.json is recommended for identifying dependencies that utilize these hooks [4].
Citations:
Do not run dispatcher-selected refs with the automation key.
workflow_dispatchrequires write access, and this job checks out$inputs.branchwithDATA_PIPELINE_PR_AUTOMATION_KEYbeforenpm install. Even if root install scripts are disabled, selected repository code can still execute with that credential and expose it. Remove thebranchinput, checkoutmain, use the scopedGITHUB_TOKEN, and setpersist-credentials: false. If non-main refs are required, run them in a separate job without write permissions or secrets.🤖 Prompt for AI Agents
Source: Linters/SAST tools