Skip to content
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

🦙 Update rules to use gatsby-plugin-mdx #1571

Open
wants to merge 46 commits into
base: tina/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8ed57ac
Add gatsby-plugin-mdx
tkapa Oct 3, 2024
f043957
Merge branch 'tina/main' of https://github.com/SSWConsulting/SSW.Rule…
tkapa Oct 4, 2024
9c11578
Update gatsby-node
tkapa Oct 4, 2024
9612942
changed allMarkdownRemark instances to allMdx & reinstalled gatsby-tr…
Oct 10, 2024
5ff4641
removed all html from graphql queries
Oct 10, 2024
9693e29
got gatsby mdx working
Oct 11, 2024
aa13b37
commiting files to share with tylah
Oct 14, 2024
491abd4
Merge branch 'tina/main' into tina/call-mdx
Oct 14, 2024
3574470
got rules/rule working with gatsby-mdx
Oct 14, 2024
e4aff3b
got rule template working with gatsby mdx
Oct 14, 2024
f9a6b8d
Got category page working with gatsby mdx?
Oct 14, 2024
1025dcb
🔇 Removed console logs
Oct 14, 2024
cf21f43
Got intro rendering for rule categories
Oct 14, 2024
a19159a
🦙 rendering category into using TinaMarkown
Oct 14, 2024
c2778fe
🐛 Got category blurbs working
Oct 15, 2024
7d415c0
💬 uncommented method for building out archive rules
Oct 15, 2024
fc4dfeb
removed console logging
Oct 15, 2024
9feb53f
removed experimental transformer plugin
Oct 15, 2024
71be27e
Merge branch 'tina/main' into tina/call-mdx
Oct 15, 2024
1617736
fixed orphaned page
Oct 16, 2024
af6397c
Added graphql field for Tina markdown
Oct 16, 2024
5a35bc7
Fixed landing page
Oct 16, 2024
f170982
uncommented 404 page
Oct 16, 2024
452a607
Fixed archive page
Oct 16, 2024
abfde5b
uncommented search page
Oct 16, 2024
0aaf948
uncommented latest rules
Oct 16, 2024
b917c8b
uncommented rule page
Oct 16, 2024
5f55f7e
uncommented sidebar props on rule template
Oct 16, 2024
63481dd
uncommented gatsby source git for assets
Oct 16, 2024
8120915
removed console logs in gatsby-node
Oct 16, 2024
56db78a
Added index to frontmatter type in gatsby node
Oct 21, 2024
33bfb7a
removed console logs in category page template
Oct 21, 2024
11b5a15
uncommented index prop for category pages
Oct 21, 2024
db34ae7
Added todo for removing gatsby parser plugins
Oct 21, 2024
4fa381f
🚀 Created CI/CD to test tina mdx build
Oct 21, 2024
6c1ce06
specified a different content branch in tina mdx github workflow
Oct 22, 2024
8c97146
moved template build and deploy actions for mdx to root of workflows
Oct 22, 2024
1735611
Added workflow dispatch trigger for tina build & deploy action
Oct 22, 2024
e7816ea
replaced environment variables for branch with desired test branch
Oct 22, 2024
710c782
renamed actions for testing build against tina pipeline
Oct 22, 2024
d96a339
commented out rule creation step for testing purposes
Oct 22, 2024
ff1fec1
Added console logging to gatsbt-node.js to figure out where rules is …
Calinator444 Oct 22, 2024
df12ce5
deleted base pages
Oct 22, 2024
b32aa5b
removed profile page create step from gatsby node
Oct 22, 2024
f0a880c
removed categoryTemplate & rule template from gatsby-node
Oct 22, 2024
295c8dc
using custom exceprt field for algolia queries
Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/pr-build-deploy-tina.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PR - Build and Deploy Tina


on:
pull_request:
branches:
- tina/main
workflow_dispatch:

jobs:
build:
name: Build
uses: ./.github/workflows/template-build-mdx.yml
with:
branch_name: tina/call-mdx
environment: staging
should_generate_commit_data: false
secrets: inherit

deploy:
concurrency:
group: tina-deploy
cancel-in-progress: false
needs: build
name: Deploy
uses: ./.github/workflows/template-deploy-mdx.yml
with:
environment: staging
storageAccountName: tinamdx
secrets: inherit
206 changes: 206 additions & 0 deletions .github/workflows/template-build-mdx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
name: Template - Build site (MDX)

on:
workflow_call:
inputs:
branch_name:
required: true
type: string
environment:
type: string
required: true
description: 'The environment to build for'
should_generate_commit_data:
type: boolean
description: 'Generate commit data for rules history. You might want to skip this on large rules changes.'
required: false
default: true

jobs:
get-content-commit-data:
name: Generate commit data
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:

- uses: actions/checkout@v4
name: Checkout SSW.Rules
with:
path: SSW.Rules
ref: ${{ inputs.branch_name }}
sparse-checkout: |
build-scripts
fetch-depth: 1

- uses: actions/checkout@v4
name: Checkout SSW.Rules.Content
with:
repository: SSWConsulting/SSW.Rules.Content
path: SSW.Rules.Content
ref: main
fetch-depth: 0

- name: Record the latest SHA for the content repo
working-directory: SSW.Rules.Content
run: |
echo '### Content repo info! 🚀' >> $GITHUB_STEP_SUMMARY
echo "Latest SHA: [$(git rev-parse HEAD)](https://github.com/SSWConsulting/SSW.Rules.Content/commit/$(git rev-parse HEAD))" >> $GITHUB_STEP_SUMMARY


- name: Get Rule History Commits
shell: pwsh
run: |
./SSW.Rules/build-scripts/update-rule-history.ps1 `
-AzFunctionBaseUrl ${{ vars.AzFunctionBaseUrl }} `
-GetHistorySyncCommitHashKey ${{ secrets.GETHISTORYSYNCCOMMITHASHFUNCTIONKEY }} `
-UpdateRuleHistoryKey ${{ secrets.UPDATERULEHISTORYFUNCTIONKEY }} `
-UpdateHistorySyncCommitHashKey ${{ secrets.UPDATEHISTORYSYNCCOMMITHASHFUNCTIONKEY }} `
-ShouldGenerateHistory ${{ inputs.should_generate_commit_data }}

- name: Get Rule History JSON
shell: pwsh
run: |
mkdir static
./SSW.Rules/build-scripts/get-rule-history.ps1 `
-AzFunctionBaseUrl ${{ vars.AzFunctionBaseUrl }} `
-GenerateHistoryFileFunctionKey ${{ secrets.GenerateHistoryFileFunctionKey }} `
-outputFileName ${{ github.workspace }}/static/history.json

- name: Get History Commits of Each Contributor
shell: pwsh
run: |
./SSW.Rules/build-scripts/create-commits-history.ps1 `
-Token ${{ secrets.GITHUB_TOKEN }} `
-GithubOrg ${{ github.repository_owner }} `
-GithubRepo SSW.Rules.Content `
-outputFileName ${{ github.workspace }}/static/commits.json
env:
GH_TOKEN: ${{ github.token }}

- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: commit-data
path: static
retention-days: 1

build-code:
name: Gatsby
runs-on: ubuntu-latest
needs: get-content-commit-data
environment: ${{ inputs.environment }}
steps:

- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch_name }}

- name: Download commit data artifact
uses: actions/download-artifact@v4
with:
name: commit-data
path: commit-data

- name: Move commit data
run: mv commit-data/* static/

- uses: cschleiden/replace-tokens@v1
with:
tokenPrefix: '#{'
tokenSuffix: '}'
files: .env.template*
env:
GOOGLE_ANALYTICS: ${{ vars.GOOGLE_ANALYTICS }}
DEPLOYMENT_URL: https://github.com/SSWConsulting/SSW.Rules/actions/workflows/build-deploy-production.yml
VERSION_DEPLOYED: ${{ github.run_number }}
APPINSIGHTS_INSTRUMENTATIONKEY: ${{ secrets.APPINSIGHTS_INSTRUMENTATIONKEY }}
#TODO: https://github.com/SSWConsulting/SSW.Rules/issues/1528
CONTENT_BRANCH: main-with-tina-lock
TINA_CONTENT_BRANCH: main-with-tina-lock
API_BASE_URL: ${{ vars.AZFUNCTIONBASEURL }}
AUTH0_DOMAIN: ${{ vars.AUTH0_DOMAIN }}
AUTH0_CLIENT_ID: ${{ vars.AUTH0_CLIENT_ID }}
AUTH0_REDIRECT_URI: ${{ vars.AUTH0_REDIRECT_URI }}
AUTH0_SCOPE: ${{ vars.AUTH0_SCOPE }}
GITHUB_API_PAT: ${{ secrets.CONTENT_GITHUB_TOKEN }}
DISQUS_FORUM: ${{ vars.DISQUS_FORUM }}
DISQUS_API_KEY: ${{ secrets.DISQUS_API_KEY }}
GTM_CONTAINER_ID: ${{ vars.GTM_CONTAINER_ID }}
GITHUB_ORG: ${{ github.repository_owner }}
GITHUB_REPO: SSW.Rules.Content
GATSBY_ALGOLIA_APP_ID: ${{ vars.GATSBY_ALGOLIA_APP_ID }}
GATSBY_ALGOLIA_SEARCH_KEY: ${{ secrets.GATSBY_ALGOLIA_SEARCH_KEY }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
TINA_CLIENT_ID: ${{ secrets.TINA_CLIENT_ID }}
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
TINA_BASE_PATH: ${{ vars.TINA_BASE_PATH }}

- name: Rename env file
run: |
mv .env.template .env.production
cat .env.production

# TinaCMS requires the .env file to be named .env
- name: Rename env tina file
run: |
mv .env.template_tina .env
cat .env

# - name: Cache Gatsby .cache
# uses: actions/cache@v4
# with:
# path: .cache
# key: gatsby_cache | ${{ runner.os }}
# restore-keys: |
# gatsby_cache | ${{ runner.os }}

# - name: Cache Gatsby public
# uses: actions/cache@v4
# with:
# path: public
# key: gatsby_public | ${{ runner.os }}
# restore-keys: |
# gatsby_public | ${{ runner.os }}

- name: Use Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'

- name: Install dependencies
run: yarn install --immutable

- name: Build
run: yarn build
env:
GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES: true
timeout-minutes: 60

- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: public

build-infra:
name: Infra
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch_name }}
sparse-checkout: |
infra

- name: Check the result
shell: bash
run: |
mkdir arm
az bicep build --file infra/main.bicep --outdir arm

- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: infra
path: infra
111 changes: 111 additions & 0 deletions .github/workflows/template-deploy-mdx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Template - deploy site (MDX)

on:
workflow_call:
inputs:
environment:
type: string
required: true
description: 'The environment to deploy to'
storageAccountName:
type: string
required: false
description: 'A custom appendage for the storage account name'

permissions:
id-token: write
contents: read

jobs:
deploy-infra:
name: Infra
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
sha: ${{ github.sha }}
outputs:
storageAccountName: ${{ steps.deploy.outputs.storageAccountName }}
staticWebsiteUrl: ${{ steps.deploy.outputs.staticWebsiteUrl }}
steps:
- name: Download infra artifact
uses: actions/download-artifact@v4
with:
name: infra
path: infra

- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.CALEB_MPN_SUBSCRIPTION_ID }}

- name: Generate SHA
run: echo "sha=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
env:
GITHUB_SHA: ${{ github.sha }}

- name: Deploy infra
run: |
az deployment group create \
--name ${{ env.sha }} \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--template-file infra/main.bicep \
--parameters \
customStorageAccountNames=${{ inputs.storageAccountName }}\
environmentName=${{ inputs.environment }} \
--mode Incremental

- name: Get deployment outputs
id: deploy
run: |
STORAGE_ACCOUNT_NAME=$(az deployment group show --name ${{ env.sha }} --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --query properties.outputs.storageAccountName.value -o tsv)
echo "Storage Account Name: $STORAGE_ACCOUNT_NAME"

STATIC_WEBSITE_URL=$(az storage account show --name $STORAGE_ACCOUNT_NAME --query primaryEndpoints.web -o tsv)
echo "Static Website URL: $STATIC_WEBSITE_URL"

echo "storageAccountName=$STORAGE_ACCOUNT_NAME" >> $GITHUB_OUTPUT
echo "staticWebsiteUrl=$STATIC_WEBSITE_URL" >> $GITHUB_OUTPUT

deploy:
name: Site
needs: deploy-infra
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
url: ${{ needs.deploy-infra.outputs.staticWebsiteUrl }}/rules
steps:
- name: Download code artifact
uses: actions/download-artifact@v4
with:
name: build
path: rules

- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.CALEB_MPN_SUBSCRIPTION_ID }}

- name: Upload files to Azure storage
run: |
sas=$(az storage account generate-sas \
--account-name ${{ needs.deploy-infra.outputs.storageAccountName }} \
--expiry $(date -d "tomorrow" +%Y-%m-%d) \
--permissions acdlrw \
--resource-types sco \
--services b \
--https-only \
--output tsv \
)
azcopy sync \
${{ github.workspace }} \
"https://${{ needs.deploy-infra.outputs.storageAccountName }}.blob.core.windows.net/\$web/?$sas" \
--log-level="ERROR" \
--compare-hash=MD5 --put-md5 --delete-destination=true
env:
AZCOPY_CONCURRENCY_VALUE: 256
AZCOPY_PARALLEL_STAT_FILES: true
AZCOPY_CONCURRENT_SCAN: 256
Loading
Loading