Merge pull request #94 from Kaffe-diem/typegen-action #12
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 pocketbase types | |
# PR opened, closed or updated | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
typegen: | |
name: Generate pocketbase types | |
runs-on: ubuntu-latest | |
outputs: | |
# https://github.com/orgs/community/discussions/25280 | |
commit_changes: ${{ steps.check_changes.outputs.commit_changes }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Install dependencies | |
run: npm ci | |
- name: Generate types | |
env: | |
PUBLIC_PB_HOST: ${{ vars.PB_HOST }} | |
PB_ADMIN_PASSWORD: ${{ secrets.PB_ADMIN_PASSWORD }} | |
PB_ADMIN_EMAIL: ${{ secrets.PB_ADMIN_EMAIL }} | |
run: make pb_types | |
- name: Upload generated types | |
uses: actions/upload-artifact@v4 | |
with: | |
name: generated-types | |
path: src/lib/pocketbase/index.d.ts | |
- name: Check for changes | |
id: check_changes | |
run: | | |
# https://stackoverflow.com/a/62213712 | |
if [ $(git status --porcelain | wc -l ) -gt 0 ]; then | |
echo 'commit_changes=true' >> $GITHUB_OUTPUT | |
else | |
echo 'commit_changes=false' >> $GITHUB_OUTPUT | |
fi | |
pr: | |
name: Create pull request | |
needs: [typegen] | |
if: needs.typegen.outputs.commit_changes == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download generated types | |
uses: actions/download-artifact@v4 | |
with: | |
name: generated-types | |
path: src/lib/pocketbase/ | |
- name: Configure git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
- name: Set branch name | |
run: | | |
echo "branch=typegen-$(date +%s)" >> $GITHUB_ENV | |
- name: Commit and push changes | |
run: | | |
git checkout -b "$branch" | |
git add --force src/lib/pocketbase/index.d.ts | |
git commit -m "chore: update pocketbase types" | |
git push origin "$branch" | |
- name: Create pull request | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh pr create --base "main" \ | |
--head "$branch" \ | |
--title "Update pocketbase types" \ | |
--body "Updated at $(date -Iminutes)" \ | |
--label "typegen" |