Generate GitHub Skyline #8
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
name: Generate GitHub Skyline | |
on: | |
schedule: | |
- cron: '0 0 2 * *' # Runs at midnight on the 2nd day of every month | |
workflow_dispatch: # Allows manual triggering of the workflow | |
jobs: | |
generate-skyline: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: Install GitHub CLI | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provides authentication for GitHub CLI | |
run: | | |
sudo apt update | |
sudo apt install -y gh | |
- name: Install gh-skyline extension | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provides authentication for installing extensions | |
run: | | |
gh extension install github/gh-skyline | |
- name: Calculate year and run command | |
id: skyline | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provides authentication for GitHub CLI commands | |
run: | | |
YEAR=$(date --date="$(date +%Y-%m-02) -1 month" +%Y) | |
MONTH_NAME=$(date --date="$(date +%Y-%m-02)" +%B) | |
FILENAME="assets/gh-stl/davidsneighbour-${YEAR}-github-skyline.stl" | |
REPO_OWNER=$(gh repo view --json owner --jq '.owner.login') | |
gh skyline --user $REPO_OWNER --output $FILENAME --year $YEAR | |
echo "FILENAME=$FILENAME" >> $GITHUB_ENV | |
echo "YEAR=$YEAR" >> $GITHUB_ENV | |
- name: Set up Git user from repo | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provides authentication for GitHub CLI commands | |
run: | | |
REPO_OWNER=$(gh repo view --json owner --jq '.owner.login') | |
USER_EMAIL="${REPO_OWNER}@users.noreply.github.com" | |
git config user.name "$REPO_OWNER" | |
git config user.email "$USER_EMAIL" | |
- name: Commit and push changes | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provides authentication for GitHub CLI commands | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
git add $FILENAME | |
git commit -m "chore(assets): update skyline stats for $YEAR" | |
git push | |
else | |
echo "No changes to commit. Exiting." | |
fi |