Skip to content

update-activity-content #1534

update-activity-content

update-activity-content #1534

name: update-activity-content
on:
schedule:
- cron: '47 5,21 * * *'
push:
branches:
- 'main'
paths:
- '.github/*.ts'
- 'tasks/graphql/**'
- '_config.ts'
- 'deno.json'
- 'member/**'
- 'site/**'
repository_dispatch:
workflow_dispatch:
inputs:
about:
description: Regenerate about (CONTACTS.yaml) and sponsors information
type: boolean
default: false
permissions:
contents: read
env:
GH_BOT_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
GH_BOT_NAME: "GitHub Action"
DENO_DIR: .deno-cache
REPO: commonhaus/commonhaus.github.io
LAST_ABOUT: "site/_generated/.last_about"
jobs:
build_refresh:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
concurrency:
group: "push-content"
outputs:
updated: steps.git-push.outputs.updated || steps.submodule.outputs.updated || steps.about.outputs.updated || steps.discussion.outputs.updated
votes_updated: steps.count_votes.outputs.votes_updated
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
- name: Cache node modules
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: node_modules
key: ${{ hashFiles('deno.lock') }}
- name: Cache Deno dependencies
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: ${{ env.DENO_DIR }}
key: ${{ hashFiles('deno.lock') }}
- name: Setup Deno environment
uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb # v2.0.3
with:
deno-version: v2.x
- name: Build info
run: deno info
- name: Git Config
run: |
git config user.name ${{ env.GH_BOT_NAME }}
git config user.email ${{ env.GH_BOT_EMAIL }}
- id: git-push
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
echo "updated=true" >> $GITHUB_OUTPUT
- name: Git Submodule Update
id: submodule
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git pull --recurse-submodules
git submodule update --init --remote --recursive
deno task lastmod
if git diff --quiet; then
echo "-- No changes -- "
else
git commit -am "πŸ†™ Auto-update submodule references"
git pull --rebase
git push
echo "updated=true" >> $GITHUB_OUTPUT
fi
- name: Check for changes in foundation submodule
id: check_changes
env:
LAST_ABOUT: ${{ env.LAST_ABOUT }}
RUN_ABOUT: ${{ inputs.about }}
run: |
# Check last run timestamp
CURRENT_TIME=$(date +%s)
DAYS_THRESHOLD=7
function refresh() {
local file=$1
local input=$2
if [ -f "${file}" ]; then
local last=$(cat "${file}")
local days_diff=$(( (${CURRENT_TIME} - ${last}) / 86400 ))
if [ ${days_diff} -ge ${DAYS_THRESHOLD} ]; then
echo "true"
else
echo "${input}"
fi
else
echo "true"
fi
}
# Check for changes in the foundation submodule
pushd foundation-content > /dev/null
DIFF_FILES=$(git diff --name-only HEAD~1 HEAD)
# Exit if git diff fails
if [ $? -ne 0 ]; then
echo "Error: Failed to run git diff" >&2
exit 1
fi
CONTACTS_CHANGED=$(echo "$DIFF_FILES" | grep -q "CONTACTS.yaml" && echo "true" || echo "false")
PROJECTS_CHANGED=$(echo "$DIFF_FILES" | grep -q "PROJECTS.yaml" && echo "true" || echo "false")
popd > /dev/null
# Determine if updates are needed
REFRESH_ABOUT=$(refresh "${LAST_ABOUT}" "${RUN_ABOUT}")
UPDATE_ABOUT="false"
if [[ "${REFRESH_ABOUT}" == "true" || "${CONTACTS_CHANGED}" == "true" || "${PROJECTS_CHANGED}" == "true" ]]; then
UPDATE_ABOUT="true"
fi
echo "refresh_required=$REFRESH_ABOUT" >> $GITHUB_OUTPUT
echo "update_required=$UPDATE_ABOUT" >> $GITHUB_OUTPUT
- name: Foundation Metadata Update
id: about
if: steps.check_changes.outputs.update_required
env:
GH_TOKEN: ${{ secrets.WEB_REPO_READ }}
LAST_ABOUT: ${{ env.LAST_ABOUT }}
REFRESH_ABOUT: ${{ steps.check_changes.outputs.refresh_required }}
run: |
if ! deno task about; then
echo "Error: Failed to run deno task about" >&2
exit 1
fi
# Update the timestamp only if content changes or threshold expired
git add -A -- ./site/_generated/about.yml
if [[ "${REFRESH_ABOUT}" == "true" ]] || ! git diff --quiet HEAD; then
echo "Content changes detected or refresh threshold expired. Committing updates..."
date +%s > ${LAST_ABOUT}
git add ${LAST_ABOUT}
git commit -am "πŸ‘₯ Auto-update foundation metadata"
git pull --rebase
git push
echo "updated=true" >> $GITHUB_OUTPUT
else
echo "-- No changes -- "
fi
- name: Git Discussion Update
id: discussion
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! deno task activity; then
echo "Error: Failed to run deno task activity" >&2
exit 1
fi
git add -A -- ./site/_generated/activity ./site/_generated/authors.yml
if git diff --quiet HEAD; then
echo "-- No changes -- "
else
git commit -am "πŸ’¬ Auto-update GH Activity"
git pull --rebase
git push
echo "updated=true" >> $GITHUB_OUTPUT
fi
- name: Count votes
id: count_votes
uses: commonhaus/vote-record-actions/actions/count-votes@1.0.8
with:
repositories: "commonhaus/foundation"
target_dir: "site/_generated/votes"
branch: "main"
update:
needs: build_refresh
if: needs.build_refresh.outputs.votes_updated || needs.build_refresh.outputs.updated
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Push GH Pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run -R commonhaus/commonhaus.github.io gh-pages.yml