Skip to content

Commit 613b6a2

Browse files
Get CI working
Update `@types/ms` resolution to version 0.7.32 in `package.json` and `yarn.lock`. Add ts-node script and update linting commands in package.json and lint.sh. Enhance CI workflow with debug info for PR events; add new blog post template and assets. Refactor types in find-markdown.ts and add test PR event JSON file. Refactor PR file handling: update to use 'files' instead of 'added_files' for added file tracking in GitHub Actions. Adjust test data accordingly. Remove debug logging and add base branch environment variable in workflows Enhance GitHub Actions workflow: add branch info echo and ensure make step before linting. Refactor linting scripts and update pull request workflow - Removed lint step from GitHub Actions workflow - Simplified the `find-markdown.ts` script by removing GHA-related functionality - Updated `getGitModifiedFiles` to accept a base branch parameter - Resolved types and streamlined logic for markdown file detection - Adjusted lint scripts to handle modes more effectively Update markdown linting script to exclude 'node_modules' directory and add debug logging functionality in the linting process. Set DEBUG mode to off by default. Update GitHub Actions workflow and improve file detection logic - Upgraded `actions/checkout` from v2 to v4 and set fetch depth. - Enhanced `getGitModifiedFiles` function to handle both local and GitHub Actions environments. - Improved error handling and added debug logging for file detection. Refactor GitHub Actions workflow and TypeScript script for enhanced efficiency and clarity in fetching branches and modified files.
1 parent 0cee3de commit 613b6a2

File tree

10 files changed

+268
-55
lines changed

10 files changed

+268
-55
lines changed

.github/workflows/pull-request.yml

+27-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,35 @@ jobs:
1919
environment: testing
2020
steps:
2121

22-
- uses: actions/checkout@v2
23-
22+
- uses: actions/checkout@v4
23+
with:
24+
# Only fetch PR branch
25+
fetch-depth: 1
26+
ref: ${{ github.event.pull_request.head.sha }}
27+
28+
- name: Fetch base branch
29+
run: |
30+
# Fetch and create local master branch
31+
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin master:master
32+
# Verify branches
33+
echo "Local branches:"
34+
git branch -v
35+
echo "\nRemote branches:"
36+
git branch -r
37+
38+
- name: Set base branch env
39+
run: |
40+
if [ "${{ github.event_name }}" = "pull_request" ]; then
41+
echo "BASE_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
42+
else
43+
# This covers push scenario to master
44+
# or any other scenario with no PR info
45+
echo "BASE_BRANCH=" >> $GITHUB_ENV
46+
fi
47+
echo "Branch:${{ github.event.pull_request.base.ref }}"
2448
- uses: actions/setup-node@v1
2549
with:
2650
node-version: '18.x'
27-
2851
- uses: peaceiris/actions-hugo@v2
2952
with:
3053
hugo-version: '0.135.0'
@@ -55,6 +78,7 @@ jobs:
5578
ALGOLIA_APP_SEARCH_KEY: ${{ vars.ALGOLIA_APP_SEARCH_KEY }}
5679
ALGOLIA_APP_ADMIN_KEY: ${{ secrets.ALGOLIA_APP_ADMIN_KEY }}
5780
NODE_OPTIONS: "--max_old_space_size=8192"
81+
BASE_BRANCH: ${{ env.BASE_BRANCH }}
5882

5983
- name: Archive test results
6084
uses: actions/upload-artifact@v4

content/blog/sfsdfsfs/index.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: "Sfsdfsfs"
3+
4+
# The date represents the post's publish date, and by default corresponds with
5+
# the date and time this file was generated. Dates are used for display and
6+
# ordering purposes only; they have no effect on whether or when a post is
7+
# published. To influence the ordering of posts published on the same date, use
8+
# the time portion of the date value; posts are sorted in descending order by
9+
# date/time.
10+
date: 2025-02-04T10:14:44-05:00
11+
12+
# The draft setting determines whether a post is published. Set it to true if
13+
# you want to be able to merge the post without publishing it.
14+
draft: false
15+
16+
# Use the meta_desc property to provide a brief summary (one or two sentences)
17+
# of the content of the post, which is useful for targeting search results or
18+
# social-media previews. This field is required or the build will fail the
19+
# linter test. Max length is 160 characters.
20+
meta_desc:
21+
22+
# The meta_image appears in social-media previews and on the blog home page. A
23+
# placeholder image representing the recommended format, dimensions and aspect
24+
# ratio has been provided for you.
25+
meta_image: meta.png
26+
27+
# At least one author is required. The values in this list correspond with the
28+
# `id` properties of the team member files at /data/team/team. Create a file for
29+
# yourself if you don't already have one.
30+
authors:
31+
- joe-duffy
32+
33+
# At least one tag is required. Lowercase, hyphen-delimited is recommended.
34+
tags:
35+
- change-me
36+
37+
38+
# The social copy used to promote this post on Twitter and Linkedin. These
39+
# properties do not actually create the post and have no effect on the
40+
# generated blog page. They are here strictly for reference.
41+
42+
# Here are some examples of posts we have made in the past for inspiration:
43+
# https://www.linkedin.com/feed/update/urn:li:activity:7171191945841561601
44+
# https://www.linkedin.com/feed/update/urn:li:activity:7169021002394296320
45+
# https://www.linkedin.com/feed/update/urn:li:activity:7155606616455737345
46+
# https://twitter.com/PulumiCorp/status/1763265391042654623
47+
# https://twitter.com/PulumiCorp/status/1762900472489185492
48+
# https://twitter.com/PulumiCorp/status/1755637618631405655
49+
50+
social:
51+
twitter:
52+
linkedin:
53+
54+
# See the blogging docs at https://github.com/pulumi/docs/blob/master/BLOGGING.md
55+
# for details, and please remove these comments before submitting for review.
56+
---
57+
58+
What you put here will appear on the index page. In most cases, you'll also want to add a Read More link after this paragraph (though technically, that's optional. To do that, just add an HTML comment like the one below.
59+
60+
<!--more-->
61+
62+
And then everything _after_ that comment will appear on the post page itself.
63+
64+
Either way, avoid using images or code samples [in the first 70 words](https://gohugo.io/content-management/summaries/#automatic-summary-splitting) of your post, as these may not render properly in summary contexts (e.g., on the blog home page or in social-media previews).
65+
66+
## Writing the Post
67+
68+
For help assembling the content of your post, see [BLOGGING.md](https://github.com/pulumi/docs/blob/master/BLOGGING.md). For general formatting guidelines, see the [Style Guide](https://github.com/pulumi/docs/blob/master/STYLE-GUIDE.md).
69+
70+
## Code Samples
71+
72+
```typescript
73+
let bucket = new aws.s3.Bucket("stuff");
74+
...
75+
```
76+
77+
## Images
78+
79+
![Placeholder Image](meta.png)
80+
81+
## Videos
82+
83+
{{< youtube "kDB-YRKFfYE?rel=0" >}}
84+
85+
Note the `?rel=0` param, which tells YouTube to suggest only videos from same channel.

content/blog/sfsdfsfs/meta.png

24.1 KB
Loading

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"license": "Apache-2.0",
66
"scripts": {
77
"minify-css": "node scripts/minify-css.js",
8-
"prepare": "husky"
8+
"prepare": "husky",
9+
"ts-node": "ts-node"
910
},
1011
"dependencies": {
1112
"@aws-sdk/client-s3": "^3.427.0",
@@ -40,6 +41,9 @@
4041
"zod": "^3.24.1",
4142
"zod-matter": "^0.1.1"
4243
},
44+
"resolutions": {
45+
"@types/ms": "0.7.32"
46+
},
4347
"devDependencies": {
4448
"@types/js-yaml": "^4.0.9",
4549
"@types/markdownlint": "^0.18.0",

scripts/lint/find-markdown.ts

+93-37
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface MarkdownFile {
2929
/**
3030
* Different modes for finding markdown files and determining if they're new
3131
*/
32-
type FinderMode = 'git' | 'gha' | 'standard';
32+
export type FinderMode = 'git' | 'gha';
3333

3434
const AUTO_GENERATED_HEADING_REGEX = /^> This page was automatically generated\./m;
3535

@@ -69,54 +69,97 @@ function shouldExcludeByFrontMatter(frontMatter: FrontMatter | undefined): boole
6969
import { debug } from './utils';
7070

7171
/**
72-
* Get list of files modified in the latest git commit
72+
* Get list of files that are newly added in the current branch compared to base branch,
73+
* including staged and unstaged changes. Handles both local git and GitHub Actions environments.
7374
*/
74-
function getGitModifiedFiles(): Set<string> {
75+
function getGitModifiedFiles(baseBranch?: string): Set<string> {
7576
try {
7677
debug('Getting git modified files...');
77-
const output = execSync('git diff-tree --no-commit-id --name-only -r HEAD', { encoding: 'utf8' });
78-
const set = new Set(output.split('\n').filter(Boolean));
79-
debug('Modified files:', set);
80-
return set;
81-
} catch (error) {
82-
console.warn('Failed to get git modified files, treating all files as existing');
83-
return new Set<string>();
84-
}
85-
}
78+
const newFiles = new Set<string>();
79+
80+
// In GitHub Actions, use FETCH_HEAD since we just fetched the base branch
81+
const isGHA = process.env.GITHUB_ACTIONS === 'true';
82+
const baseRef = isGHA ? 'FETCH_HEAD' : (baseBranch || process.env.BASE_BRANCH || 'master');
83+
debug('Using base ref:', baseRef);
84+
85+
try {
86+
// In GHA, we've just fetched the base branch to FETCH_HEAD, so this is safe
87+
const diffOutput = execSync(`git diff --name-status HEAD ${baseRef}`, { encoding: 'utf8' });
88+
debug('Got diff output');
89+
diffOutput.split('\n')
90+
.filter(line => line.startsWith('A\t'))
91+
.map(line => line.split('\t')[1])
92+
.forEach(file => newFiles.add(file));
93+
} catch (error) {
94+
debug('Diff failed:', error);
95+
if (isGHA) {
96+
// In GHA, if diff fails, something is wrong with our setup
97+
throw error;
98+
}
99+
// In local dev, try to get staged/untracked files
100+
debug('Falling back to staged/untracked files only');
101+
}
86102

87-
/**
88-
* Get list of files modified in the current PR (GitHub Actions)
89-
*/
90-
function getGHAModifiedFiles(): Set<string> {
91-
const eventPath = process.env.GITHUB_EVENT_PATH;
92-
if (!eventPath) {
93-
console.warn('No GITHUB_EVENT_PATH found, treating all files as existing');
94-
return new Set<string>();
95-
}
103+
// In local dev, also look for staged and untracked files
104+
if (!isGHA) {
105+
try {
106+
// Get new files from staged changes
107+
const stagedFiles = execSync('git diff --name-status --cached', { encoding: 'utf8' });
108+
stagedFiles.split('\n')
109+
.filter(line => line.startsWith('A\t'))
110+
.map(line => line.split('\t')[1])
111+
.forEach(file => newFiles.add(file));
112+
113+
// Get untracked files
114+
debug('Getting untracked files...');
115+
const untrackedFiles = execSync('git ls-files --others --exclude-standard --full-name', { encoding: 'utf8' });
116+
debug('Raw untracked files output:', untrackedFiles);
117+
untrackedFiles.split('\n').filter(Boolean).forEach(file => newFiles.add(file));
118+
119+
// Also get untracked markdown files specifically
120+
const untrackedMarkdown = execSync('git ls-files --others --exclude-standard --full-name "*.md"', { encoding: 'utf8' });
121+
debug('Raw untracked markdown files:', untrackedMarkdown);
122+
untrackedMarkdown.split('\n').filter(Boolean).forEach(file => newFiles.add(file));
123+
} catch (error) {
124+
debug('Failed to get staged/untracked files:', error);
125+
}
126+
}
96127

97-
try {
98-
const event = JSON.parse(fs.readFileSync(eventPath, 'utf8'));
99-
const files = event.pull_request?.changed_files || [];
100-
return new Set(files);
128+
debug('Found new files:', newFiles);
129+
return newFiles;
101130
} catch (error) {
102-
console.warn('Failed to get PR modified files, treating all files as existing');
131+
console.warn('Failed to get git modified files:', error);
132+
if (process.env.GITHUB_ACTIONS === 'true') {
133+
console.warn('Running in GitHub Actions - treating all files as existing');
134+
} else {
135+
console.warn('Running locally - treating all files as existing');
136+
}
103137
return new Set<string>();
104138
}
105139
}
106140

141+
142+
107143
/**
108-
* Find all markdown files in the given directory and its subdirectories.
144+
* Find all markdown files in the given directory and its subdirectoriesA
109145
* Optionally marks files as new based on git/GHA context.
110146
*/
111147
export function findMarkdownFiles(
112148
rootDir: string,
113-
mode: FinderMode = 'standard',
114-
excludePaths: string[] = ['/content/docs/reference/pkg', '/content/registry']
149+
mode: FinderMode = 'git',
150+
excludePaths: string[] = ['/content/docs/reference/pkg', '/content/registry', '/node_modules']
115151
): MarkdownFile[] {
116152
const files: MarkdownFile[] = [];
117-
const modifiedFiles = mode === 'git' ? getGitModifiedFiles()
118-
: mode === 'gha' ? getGHAModifiedFiles()
119-
: new Set<string>();
153+
154+
// Determine which files are considered new based on mode
155+
let modifiedFiles = new Set<string>();
156+
if (mode === 'git') {
157+
modifiedFiles = getGitModifiedFiles();
158+
} else if (mode === 'gha') {
159+
const baseBranch = process.env.BASE_BRANCH;
160+
debug('GHA mode using base branch:', baseBranch);
161+
modifiedFiles = getGitModifiedFiles(baseBranch);
162+
}
120163

121164
function isExcluded(filePath: string): boolean {
122165
return excludePaths.some(excludePath => filePath.includes(excludePath));
@@ -142,9 +185,11 @@ export function findMarkdownFiles(
142185
const content = fs.readFileSync(fullPath, 'utf8');
143186
const frontMatter = parseFrontMatter(fullPath);
144187
if (!shouldExcludeByFrontMatter(frontMatter)) {
188+
// Convert absolute path to relative for comparing with git modified files
189+
const relPath = path.relative(process.cwd(), fullPath);
145190
files.push({
146191
path: fullPath,
147-
isNew: modifiedFiles.has(fullPath),
192+
isNew: modifiedFiles.has(relPath),
148193
content,
149194
frontMatter
150195
});
@@ -159,8 +204,19 @@ export function findMarkdownFiles(
159204

160205
// If run directly, output found files
161206
if (require.main === module) {
162-
const mode = (process.argv[2] as FinderMode) || 'standard';
163-
const rootDir = process.argv[3] || '../../content';
164-
const files = findMarkdownFiles(rootDir, mode);
165-
console.log(JSON.stringify(files, null, 2));
207+
const mode = (process.argv[2] as FinderMode) || 'gha';
208+
const showAll = process.argv.includes('--show-all');
209+
debug('Running in mode:', mode, 'show all:', showAll);
210+
211+
// Find all markdown files
212+
const files = findMarkdownFiles('.', mode);
213+
214+
if (showAll) {
215+
console.log('All markdown files (new files marked with *):')
216+
console.log(JSON.stringify(files.map(f => `${f.isNew ? '*' : ' '} ${f.path}`), null, 2));
217+
} else {
218+
const newFiles = files.filter(f => f.isNew).map(f => f.path);
219+
console.log('New markdown files detected:');
220+
console.log(JSON.stringify(newFiles, null, 2));
221+
}
166222
}

scripts/lint/lint.sh

+18-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22

33
set -o errexit -o pipefail
44

5-
# Get script directory
6-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7-
85
DEBUG=0
96

7+
# Debug logging function
8+
debug() {
9+
if [ -n "$DEBUG" ]; then
10+
echo "[DEBUG] $1"
11+
fi
12+
}
13+
1014
# Determine mode based on environment
11-
if [ -n "$GITHUB_ACTIONS" ]; then
15+
if [ -n "$BASE_BRANCH" ]; then
1216
MODE="gha"
17+
debug "Using base branch: $BASE_BRANCH"
1318
else
1419
MODE="git"
20+
debug "Using git mode (no base branch)"
1521
fi
1622

23+
# If in debug mode, show what files would be considered new
24+
# if [ -n "$DEBUG" ]; then
25+
# debug "Preview of new files:"
26+
# yarn ts-node "./scripts/lint/find-markdown.ts" "$MODE" --show-all
27+
# fi
28+
1729
# Run markdown linting with debug flag
18-
DEBUG=$DEBUG ts-node "$SCRIPT_DIR/markdownlint-runner.ts" "$MODE"
30+
DEBUG=$DEBUG yarn ts-node "./scripts/lint/markdownlint-runner.ts" "$MODE"
1931

2032
# Run front matter validation
21-
DEBUG=$DEBUG ts-node "$SCRIPT_DIR/validate-frontmatter.ts" "$MODE"
33+
DEBUG=$DEBUG yarn ts-node "./scripts/lint/validate-frontmatter.ts" "$MODE"
2234

2335
# Run prettier
2436
yarn prettier --check .

scripts/lint/markdownlint-runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path';
2-
import { findMarkdownFiles } from './find-markdown';
2+
import { findMarkdownFiles, FinderMode } from './find-markdown';
33

44
// Types for markdownlint
55
type Token = {
@@ -61,7 +61,7 @@ function groupLintErrorOutput(result: Record<string, LintError[]>): LintResult[]
6161
import { debug } from './utils';
6262

6363
// Get mode from command line args, defaulting to 'standard'
64-
const mode = (process.argv[2] as 'git' | 'gha' | 'standard') || 'standard';
64+
const mode = (process.argv[2] as FinderMode) || 'git';
6565
debug('Running in mode:', mode);
6666

6767
// Get markdown files to lint

0 commit comments

Comments
 (0)