Skip to content

Commit 510a5ad

Browse files
committed
test: first commit for workflow
0 parents  commit 510a5ad

File tree

1,428 files changed

+267214
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,428 files changed

+267214
-0
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Build Transcripts Preview Site
2+
permissions:
3+
contents: read
4+
pull-requests: write
5+
issues: write
6+
on:
7+
pull_request_target:
8+
paths:
9+
- '**'
10+
workflow_dispatch:
11+
issue_comment:
12+
types: [created]
13+
14+
jobs:
15+
build-preview:
16+
runs-on: ubuntu-latest
17+
18+
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external-fork-preview' || '' }}
19+
20+
if: |
21+
github.event_name == 'workflow_dispatch' ||
22+
github.event_name == 'pull_request_target' ||
23+
(github.event_name == 'issue_comment' &&
24+
github.event.issue.pull_request &&
25+
contains(github.event.comment.body, '/build-preview') &&
26+
(github.event.comment.author_association == 'OWNER' ||
27+
github.event.comment.author_association == 'MEMBER' ||
28+
github.event.comment.author_association == 'COLLABORATOR'))
29+
30+
steps:
31+
- name: Get PR details for comment trigger
32+
id: pr-details
33+
if: github.event_name == 'issue_comment'
34+
uses: actions/github-script@v7
35+
with:
36+
result-encoding: string
37+
script: |
38+
const pr = await github.rest.pulls.get({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
pull_number: context.issue.number
42+
});
43+
return JSON.stringify({
44+
head_sha: pr.data.head.sha,
45+
head_ref: pr.data.head.ref,
46+
head_repo_fullname: pr.data.head.repo.full_name
47+
});
48+
49+
- name: Setup Checkout for Bitcoin Transcripts (PR Target)
50+
if: github.event_name == 'pull_request_target'
51+
uses: actions/checkout@v4
52+
with:
53+
repository: ${{ github.event.pull_request.head.repo.full_name }}
54+
ref: ${{ github.event.pull_request.head.sha }}
55+
path: transcripts
56+
57+
- name: Setup Checkout for Bitcoin Transcripts (Comment Trigger)
58+
if: github.event_name == 'issue_comment'
59+
uses: actions/checkout@v4
60+
with:
61+
repository: ${{ fromJson(steps.pr-details.outputs.result).head_repo_fullname }}
62+
ref: ${{ fromJson(steps.pr-details.outputs.result).head_sha }}
63+
path: transcripts
64+
65+
- name: Setup Checkout for Bitcoin Transcripts (Workflow Dispatch)
66+
if: github.event_name == 'workflow_dispatch'
67+
uses: actions/checkout@v4
68+
with:
69+
path: transcripts
70+
71+
- name: Setup Node.js 20
72+
uses: actions/setup-node@v4
73+
with:
74+
node-version: 20
75+
76+
- name: Clone Registry Repo
77+
run: git clone https://github.com/bitcointranscripts/registry.git
78+
79+
- name: Replace the public/bitcoin-transcript submodule in Registry with contents of this current branch
80+
working-directory: transcripts
81+
run: |
82+
rm -rf ../registry/public/bitcoin-transcript
83+
mkdir -p ../registry/public/bitcoin-transcript
84+
cp -r * ../registry/public/bitcoin-transcript/
85+
86+
- name: Install dependencies
87+
working-directory: registry
88+
run: |
89+
npm install
90+
91+
- name: Run Next.js build only
92+
working-directory: registry
93+
env:
94+
API_KEY: ${{ secrets.API_KEY }}
95+
CLOUD_ID: ${{ secrets.CLOUD_ID }}
96+
INDEX: ${{ secrets.INDEX }}
97+
98+
run: |
99+
npm run fetch-topics
100+
npm run fetch-reviewers
101+
npx next build
102+
103+
- name: Install Vercel CLI
104+
run: npm install -g vercel
105+
106+
- name: Add vercel.json with custom build-only command
107+
working-directory: registry
108+
run: |
109+
cat <<EOF > vercel.json
110+
{
111+
"buildCommand": "npm run fetch-topics && npm run fetch-reviewers && npx next build"
112+
}
113+
EOF
114+
115+
- name: Pull Vercel project settings
116+
working-directory: registry
117+
env:
118+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
119+
run: vercel pull --yes --token=$VERCEL_TOKEN
120+
121+
- name: Build with Vercel CLI
122+
working-directory: registry
123+
env:
124+
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
125+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
126+
API_KEY: ${{ secrets.API_KEY }}
127+
CLOUD_ID: ${{ secrets.CLOUD_ID }}
128+
INDEX: ${{ secrets.INDEX }}
129+
run: vercel build --token=$VERCEL_TOKEN
130+
131+
- name: Deploy to Vercel
132+
working-directory: registry
133+
env:
134+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
135+
run: |
136+
vercel deploy --prebuilt --token=$VERCEL_TOKEN --archive=tgz --yes > ../vercel-preview-url.txt
137+
138+
- name: Store Top-Level Folders
139+
working-directory: transcripts
140+
run: |
141+
git remote add upstream https://github.com/bitcointranscripts/bitcointranscripts.git
142+
git fetch upstream
143+
top_level_folders=$(git diff --name-only upstream/master)
144+
echo $top_level_folders > ../top_level_folders.txt
145+
146+
- name: Comment PR with Preview URL
147+
uses: actions/github-script@v7
148+
with:
149+
script: |
150+
const fs = require('fs');
151+
const url = fs.readFileSync('vercel-preview-url.txt', 'utf8').trim();
152+
const top_level_folders = fs.readFileSync('top_level_folders.txt', 'utf8').trim();
153+
const dirs = top_level_folders.split(' ');
154+
let commentBody = `Your Transcript Preview is ready:\n`;
155+
if (dirs.length >= 1) {
156+
for (const dir of dirs) {
157+
if(dir.includes(".md")) {
158+
let dir_name = dir.replace(".md", "");
159+
commentBody += `- [${dir_name}](${url}/${dir_name})\n`;
160+
}
161+
}
162+
commentBody += `- [View All Transcript Sources](${url}/sources)\n`;
163+
}
164+
165+
const prNumber = context.issue?.number || context.payload.pull_request?.number;
166+
167+
github.rest.issues.createComment({
168+
issue_number: prNumber,
169+
owner: context.repo.owner,
170+
repo: context.repo.repo,
171+
body: commentBody
172+
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: metadata-linter
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, synchronize]
7+
8+
jobs:
9+
yaml-lint-and-validate:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: '3.x'
18+
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install yamllint pyyaml
23+
24+
- name: Extract YAML front matter (excluding root directory and _index files)
25+
run: |
26+
find . -mindepth 2 -name "*.md" | while read file; do
27+
base=$(basename "$file")
28+
if [[ "$base" != _index* ]] && [[ "$dir" != ./.github/workflows* ]]; then
29+
dir=$(dirname "$file")
30+
base_no_ext=$(basename "$file" .md)
31+
sed -n '/^---$/,/^---$/p' "$file" > "${dir}/${base_no_ext}.yml"
32+
fi
33+
done
34+
35+
- name: YAML Lint (excluding root directory)
36+
uses: ibiqlik/action-yamllint@v3
37+
with:
38+
file_or_dir: .
39+
config_file: .yamllint.yml
40+
41+
- name: Validate YAML structure
42+
run: |
43+
import os
44+
import yaml
45+
46+
def validate_yaml(file_path):
47+
with open(file_path, 'r') as file:
48+
content = file.read().strip()
49+
if not content:
50+
return False, f"Error: {file_path} is empty"
51+
content = content.strip('-').strip()
52+
53+
if not content:
54+
return False, f"Error: {file_path} does not contain any YAML content after removing '---' lines"
55+
56+
try:
57+
data = yaml.safe_load(content)
58+
if data is None:
59+
return False, f"Error: {file_path} does not contain any YAML content"
60+
if not isinstance(data, dict):
61+
return False, f"Error: {file_path} YAML content is not a dictionary"
62+
63+
# Check for required 'title' field
64+
if 'title' not in data:
65+
return False, f"Error in {file_path}: Missing required key: title"
66+
67+
# Check for unexpected fields
68+
allowed_fields = ['title', 'date', 'summary', 'episode', 'additional_resources', 'speakers', 'tags', 'media', 'source_file', 'transcript_by', 'categories', 'aliases', 'translation_by', 'needs']
69+
unexpected_fields = [key for key in data.keys() if key not in allowed_fields]
70+
if unexpected_fields:
71+
return False, f"Error in {file_path}: Unexpected fields: {', '.join(unexpected_fields)}"
72+
73+
return True, None
74+
except yaml.YAMLError as e:
75+
return False, f"Error parsing {file_path}: {e}"
76+
77+
def main():
78+
all_valid = True
79+
yaml_files_count = 0
80+
invalid_files_count = 0
81+
errors = []
82+
83+
for root, dirs, files in os.walk('.'):
84+
if root == '.' or root.startswith('./.github/workflows'):
85+
continue # Skip the root directory and .github/workflows
86+
for file in files:
87+
if file.endswith('.yml') and not file.startswith('_index'):
88+
yaml_files_count += 1
89+
full_path = os.path.join(root, file)
90+
is_valid, error_message = validate_yaml(full_path)
91+
if not is_valid:
92+
all_valid = False
93+
invalid_files_count += 1
94+
errors.append(error_message)
95+
96+
print("\nValidation Summary:")
97+
print(f"Total YAML files processed: {yaml_files_count}")
98+
print(f"Invalid files: {invalid_files_count}")
99+
100+
if errors:
101+
print("\nErrors:")
102+
for error in errors:
103+
print(error)
104+
105+
if not all_valid:
106+
print("\nValidation failed for one or more files")
107+
exit(1)
108+
else:
109+
print("\nAll files passed validation")
110+
111+
if __name__ == "__main__":
112+
main()
113+
shell: python
114+
115+
- name: Clean up temporary YAML files
116+
if: always()
117+
run: |
118+
find . -mindepth 2 -name "*.yml" -type f -not -name "_index.yml" -not -path "./.github/workflows/*" -delete
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Sync submodule updates to parent repository
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
update:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Write SSH keys
14+
run: |
15+
install -m 600 -D /dev/null ~/.ssh/id_rsa
16+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
17+
host='github.com'
18+
hosts="$(dig +short "$host" | grep -v '\.$' | sed -z 's|\n|,|g')$host"
19+
ssh-keyscan -H "$hosts" > ~/.ssh/known_hosts
20+
21+
- uses: actions/checkout@v2
22+
with:
23+
repository: bitcointranscripts/bitcointranscripts.github.io
24+
token: ${{ secrets.PRIVATE_TOKEN }}
25+
26+
- name: Pull & update submodules recursively
27+
run: |
28+
git submodule update --init --recursive
29+
git submodule update --recursive --remote
30+
- name: Commit
31+
run: |
32+
git config user.email "[email protected]"
33+
git config user.name "GitHub Actions - content update"
34+
git add --all
35+
git commit -m "content update" || echo "No changes to commit"
36+
git push

0 commit comments

Comments
 (0)