-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
245 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
name: Update new member files | ||
|
||
on: | ||
push: | ||
branches: [vladh/schema-continued] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v4 | ||
- name: Fetch main branch | ||
run: git fetch origin main:main | ||
- name: Install npm packages | ||
run: npm install | ||
- name: Update new member files | ||
run: bash ./bin/update-new-members | ||
- name: Commit member changes, if any | ||
run: bash ./bin/commit-member-changes |
This file contains 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,14 @@ | ||
#!/bin/bash -eu | ||
# Creates a commit with the changes in `src/content/members`, if any. Must be | ||
# run in the repo's root. | ||
|
||
if [[ $(git status --porcelain src/content/members) ]]; then | ||
git config user.name 'Open Source Pledge GitHub Action Runner' | ||
git config user.email '[email protected]' | ||
git add src/content/members | ||
git commit -m 'Add changes to src/content/members (automated commit)' | ||
git push | ||
echo "Changes to src/content/members committed" | ||
else | ||
echo "No changes to local member data, skipping" | ||
fi |
This file contains 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,8 @@ | ||
#!/bin/bash -eu | ||
# This script fetches the JSON files specified in `members.csv` for all | ||
# members. Must be run in the repo's root. | ||
|
||
while IFS= read -r line; do | ||
line_parts=(${line//,/ }) | ||
./bin/update-member ${line_parts[0]} ${line_parts[1]} | ||
done < members.csv |
This file contains 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,68 @@ | ||
#!/usr/bin/env node | ||
|
||
import fs from 'fs'; | ||
import fetch from 'node-fetch'; | ||
|
||
|
||
const USAGE = `USAGE: ./bin/update-member foocorp https://foocorp.example.com/foocorp.json | ||
Must be run in the repo's root.`; | ||
|
||
|
||
async function updateMember(name, url) { | ||
const localPath = `./src/content/members/${name}.json`; | ||
console.log(`Fetching member: ${name}`); | ||
console.log(`\t* Remote URL: ${url}`); | ||
console.log(`\t* Local path: ${localPath}`); | ||
|
||
let localMemberData = undefined; | ||
if (fs.existsSync(localPath)) { | ||
try { | ||
localMemberData = JSON.parse(fs.readFileSync(localPath, 'utf8')); | ||
} catch(e) { | ||
console.log(`Saw invalid JSON in ${localPath}, ignoring local data`); | ||
} | ||
} | ||
|
||
let remoteMemberData = undefined; | ||
try { | ||
remoteMemberData = await fetch(url) | ||
.then((res) => res.text()) | ||
.then((text) => JSON.parse(text)); | ||
} catch (e) { | ||
console.error(`ERROR: Failed to get JSON from ${url}`, e); | ||
process.exit(1); | ||
} | ||
|
||
let shouldWrite = (localMemberData == undefined); | ||
|
||
if (!shouldWrite) { | ||
const localMtime = new Date(localMemberData.datetimeModified); | ||
const remoteMtime = new Date(remoteMemberData.datetimeModified); | ||
shouldWrite = remoteMtime > localMtime; | ||
} | ||
|
||
if (shouldWrite) { | ||
console.log(`Remote JSON is newer, writing to ${localPath}`); | ||
try { | ||
fs.writeFileSync(localPath, JSON.stringify(remoteMemberData, null, 2)); | ||
} catch (e) { | ||
console.error(`ERROR: Failed to write to ${localPath}`, e); | ||
process.exit(1); | ||
} | ||
} else { | ||
console.log("Remote JSON is older, skipping"); | ||
} | ||
} | ||
|
||
|
||
function main() { | ||
const args = process.argv.slice(2); | ||
if (args.length != 2) { | ||
console.error(USAGE); | ||
process.exit(1); | ||
} | ||
updateMember(args[0], args[1]); | ||
} | ||
|
||
|
||
main() |
This file contains 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,17 @@ | ||
#!/bin/bash -eu | ||
# This script fetches the JSON files specified for all members that have been | ||
# added to `members.csv` compared to the `main` branch. Must be run in the | ||
# repo's root. | ||
|
||
new_member_lines=$( | ||
diff \ | ||
--changed-group-format='%>' \ | ||
--unchanged-group-format='' \ | ||
<( git show main:members.csv ) \ | ||
members.csv | ||
) || true | ||
|
||
while IFS= read -r line; do | ||
line_parts=(${line//,/ }) | ||
./bin/update-member ${line_parts[0]} ${line_parts[1]} | ||
done <<< "$new_member_lines" |
This file contains 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
sentry,https://open.sentry.io/funding/osspledge.json | ||
sentry,https://raw.githubusercontent.com/opensourcepledge/opensourcepledge.com/vladh/schema-continued/contrib/example-schema.json | ||
test,https://raw.githubusercontent.com/opensourcepledge/opensourcepledge.com/vladh/schema-continued/contrib/example-schema.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
Empty file.