-
Notifications
You must be signed in to change notification settings - Fork 5
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
Local validation for forked PRs #11
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Process newly added JSON | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: write | ||
|
||
concurrency: | ||
group: process-json-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
process-json: | ||
# Only run if the PR was merged and it is opened from a forked repo | ||
if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
# Needed to push changes back to the repo | ||
fetch-depth: 0 | ||
|
||
# Must be done before setup-node. | ||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22" | ||
cache: "yarn" | ||
cache-dependency-path: actions/yarn.lock | ||
|
||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
working-directory: ./actions | ||
|
||
- name: Find newly added JSON files | ||
id: find-json | ||
run: | | ||
# Get the list of added JSON files in the records/new/ directory | ||
ADDED_FILES=$(git diff ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} --diff-filter=A --name-only | grep '^records/new/.*\.json$' || true) | ||
echo "NEW_JSON_FILES=$ADDED_FILES" >> $GITHUB_ENV | ||
if [ -z "$ADDED_FILES" ]; then | ||
echo "No new JSON files found." | ||
fi | ||
|
||
- name: Process and move files | ||
if: env.NEW_JSON_FILES | ||
env: | ||
BLUESKY_IDENTIFIER_NODEJS_ORG: nodejs.org | ||
BLUESKY_APP_PASSWORD_NODEJS_ORG: ${{ secrets.BLUESKY_APP_PASSWORD_NODEJS_ORG }} | ||
run: | | ||
for file in $NEW_JSON_FILES; do | ||
echo "Processing $file..." | ||
node actions/process.js "$file" validate_cred_fork.js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This workflow doesn't look right? It should run validate_cred_fork.js on the files and it should not run the commit and push stuff? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It pushes changes only after logging into the account; otherwise, it will result in an error. |
||
done | ||
|
||
- name: Commit and push changes | ||
if: env.NEW_JSON_FILES | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git add records/* | ||
git commit -m "Process new JSON files from #${{ github.event.pull_request.number }}" || exit 0 | ||
git push |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fs from 'node:fs'; | ||
import process from 'node:process'; | ||
import path from 'node:path'; | ||
import { login } from './lib/login.js'; | ||
import { validateAccount, ExtendRequestReferences } from './lib/validator.js'; | ||
|
||
// The JSON file must contains the following fields: | ||
// - "account": a string field indicating the account to use to perform the action. | ||
// For it to work, this script expects BLUESKY_IDENTIFIER_$account and | ||
// BLUESKY_APP_PASSWORD_$account to be set in the environment variables. | ||
// - "action": currently "post", "repost", "quote-post", "reply" are supported. | ||
|
||
const requestFilePath = path.resolve(process.argv[2]); | ||
const request = JSON.parse(fs.readFileSync(requestFilePath, 'utf8')); | ||
|
||
// Validate the account field. | ||
const account = validateAccount(request, process.env); | ||
|
||
// Authenticate. | ||
const agent = await login(account); | ||
|
||
// Extend the post URLs in the request into { cid, uri } records. | ||
await ExtendRequestReferences(agent, request); | ||
|
||
export { agent, request, requestFilePath }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from 'node:fs'; | ||
import process from 'node:process'; | ||
import path from 'node:path'; | ||
import { validateRequest } from './lib/validator'; | ||
import assert from 'node:assert'; | ||
|
||
const requestFilePath = path.resolve(process.argv[2]); | ||
const request = JSON.parse(fs.readFileSync(requestFilePath, 'utf8')); | ||
|
||
//Check the format of the request | ||
validateRequest(request); | ||
|
||
|
||
// URL format: | ||
// 1. https://bsky.app/profile/${handle}/post/${postId} | ||
// 2. https://bsky.app/profile/${did}/post/${postId} | ||
// TODO(joyeecheung): consider supporting base other than bsky.app. | ||
const kURLPattern = /https:\/\/bsky\.app\/profile\/(.+)\/post\/(.+)/; | ||
let url; | ||
if (request.action!='post'){ | ||
switch(request.action) { | ||
case 'repost': | ||
case 'quote-post': { | ||
url=request.repostURL; | ||
break; | ||
} | ||
case 'reply': { | ||
url=request.replyURL; | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
match_url = url.match(kURLPattern); | ||
assert(match_url, `Post URL ${url} does not match the expected pattern`); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// // URI format: at://${did}/app.bsky.feed.post/${postId} | ||
// const kURIPattern = /at:\/\/(.*)+\/app\.bsky\.feed\.post\/(.*)+/ | ||
|
||
// const match_uri = uri.match(kURIPattern); | ||
// assert(match_uri, `Post URI ${uri} does not match the expected pattern`); |
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.
Let's remove this, it's unrelated with validate workflow – and not needed anyway IMO.