Skip to content

Commit

Permalink
✨ Sync Presenters from People Profiles (#2916)
Browse files Browse the repository at this point in the history
* Save progress

* Pull all data from SSW.People.Profiles

* Update TinaLock

* Implement get-people-profiles

* Update Action, add temp files to gitignore

* Remove images

* Update tinalock

* Update action

* up

* Update

* Update to keep existing values

* Update relative path

* Replace Partner images

* Update Action. Remove unnecessary files

* Update to fetch data from SSW People

* Update to save files

* Update Presenter Tsx with Skills string

* enable auto-merge

* Update

* Fix action

* Fetch People Profiles

* Revert "Merge pull request #5 from tkapa/sync/people-profiles"

This reverts commit 0a884dd, reversing
changes made to f47c21d.

* Use proper casing for files

* Fetch People Profiles

* Revert "Merge pull request #6 from tkapa/sync/people-profiles"

This reverts commit 71cc74c, reversing
changes made to 30eeb2f.

* Use capitalised for img

* Fetch People Profiles

* Revert "Merge pull request #7 from tkapa/sync/people-profiles"

This reverts commit 8d2569c, reversing
changes made to ebdfc2f.

* Run a build on the new files

* Comment out auto-merge for now

* Run a build before merge

* Add GitHub App

* Enable Auto-Merge on PR

* Fetch People Profiles (#11)

Co-authored-by: tkapa <[email protected]>

* Revert "Fetch People Profiles (#11)"

This reverts commit ab447ac.

* Add Auto flag to enable step

* Only once a week

* Mitigate Errors

* Update to use lts/*

* Reference .nvmrc

---------

Co-authored-by: tkapa <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: ssw-website-app[bot] <177506588+ssw-website-app[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 7, 2024
1 parent 7c41918 commit a7b8111
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 2 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/fetch-people-profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Weekly - Fetch SSW People Profiles

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * TUE"

env:
TEMPORARY_FOLDER: temp-profiles
SSW_PEOPLE_BASE_URL: https://ssw.com.au/people

jobs:
fetch-and-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Checkout People Profiles
uses: actions/checkout@v4
with:
repository: "SSWConsulting/SSW.People.Profiles"
path: ${{ env.TEMPORARY_FOLDER}}

- uses: actions/setup-node@v4
with:
node-version-file: ${{ env.GITHUB_WORKSPACE }}/.nvmrc

- run: corepack enable pnpm
- run: pnpm add -w gray-matter

- name: Fetch SSW.People.Profiles
uses: actions/github-script@v7
with:
script: |
const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/get-people-profiles.js`);
await script({
github,
context,
peopleBaseUrl: `${process.env.SSW_PEOPLE_BASE_URL}`,
peopleDirectory: `${process.env.GITHUB_WORKSPACE}/${ process.env.TEMPORARY_FOLDER }`,
websiteContentPath: `${process.env.GITHUB_WORKSPACE}/content`,
websitePublicPath: `${process.env.GITHUB_WORKSPACE}/public`,
presentersPath: `presenters`,
peopleImagePath: `images/people`
});
- uses: actions/create-github-app-token@v1
id: get-app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_KEY }}

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.get-app-token.outputs.token }}
commit-message: "Fetch People Profiles"
title: "Auto - Fetch People Profiles"
body: >
Created by GitHub Action.
- Syncs data from [SSW.People.Profiles](https://github.com/SSWConsulting/SSW.People.Profiles)
branch: "sync/people-profiles"
# We only expect changes to these folders
add-paths: |
content/*
public/*
- name: Enable Auto-Merge
if: ${{ steps.cpr.outputs.pull-request-number }}
run: gh pr merge -s --auto ${{ steps.cpr.outputs.pull-request-number }}
env:
GH_TOKEN: ${{ steps.get-app-token.outputs.token }}
63 changes: 63 additions & 0 deletions .github/workflows/get-people-profiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const matter = require('gray-matter');
const fs = require('fs');

const GetPeopleProfiles = async ( {
github,
context,
peopleBaseUrl,
peopleDirectory,
websiteContentPath,
websitePublicPath,
presentersPath,
peopleImagePath
} ) => {
const presentersDirectory = `${websiteContentPath}/${presentersPath}`;
const peopleImageDirectory = `${websitePublicPath}/${peopleImagePath}`;

fs.mkdirSync(presentersDirectory, { recursive: true });
fs.mkdirSync(peopleImageDirectory, { recursive: true });

try {
const people = await fetch(`${peopleBaseUrl}/people.json`);
const peopleList = await people.json();

peopleList.forEach(async person => {
console.log(`Processing ${person}`);

const contentPresenterPath = `${presentersDirectory}/${person}.mdx`;
const peopleMd = await fetch(`${peopleBaseUrl}/${person}/profile.md`);
const peopleMdStr = await peopleMd.text();

var presenterJson = {};
const peopleMatter = matter(peopleMdStr);

if (fs.existsSync(contentPresenterPath)) {
const existingPresenterFile = matter.read(contentPresenterPath);
presenterJson = existingPresenterFile.data;
}

presenterJson = {
...presenterJson,
...peopleMatter.data,
};

const personName = presenterJson.presenter?.name?.split(' ')?.join('-') ?? 'not-found';
const profileImageRelativePath = `${peopleImagePath}/${personName}.jpg`;
const peopleProfileImagePath = `${peopleDirectory}/${personName}/Images/${personName}-Profile.jpg`;

presenterJson.profileImg = presenterJson.profileImg ?? ``;

if (fs.existsSync(peopleProfileImagePath)) {
fs.copyFileSync(peopleProfileImagePath, `${websitePublicPath}/${profileImageRelativePath}`);
presenterJson.profileImg = `/${profileImageRelativePath}`;
}

console.log(`Writing ${contentPresenterPath}`);
fs.writeFileSync(contentPresenterPath, matter.stringify('', presenterJson));
});
} catch (error) {
console.log(error);
}
}

module.exports = GetPeopleProfiles;
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
/.pnp
.pnp.js
public/admin/.gitignore
.github/workflows/content
.github/workflows/public

/temp-profiles

# testing
/coverage
Expand Down Expand Up @@ -37,4 +41,4 @@ npm-debug.log*
/playwright-report

# TypeScript
next-env.d.ts
next-env.d.ts
8 changes: 8 additions & 0 deletions tina/collections/presenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const presenterSchemaConstants = {
},
about: "about",
position: "position",
skills: "skills",
};

export const presenterSchema: Collection = {
Expand Down Expand Up @@ -68,5 +69,12 @@ export const presenterSchema: Collection = {
"The presenter's occupation, e.g. Chief Architect for Adam Cogan",
required: false,
},
{
type: "string",
label: "Skills",
name: presenterSchemaConstants.skills,
description: "The presenter's skills, e.g. React | TypeScript",
required: false,
},
],
};
2 changes: 1 addition & 1 deletion tina/tina-lock.json

Large diffs are not rendered by default.

0 comments on commit a7b8111

Please sign in to comment.