Merge pull request #97 from Kaffe-diem/typegen-action #15
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 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
typegen: | |
name: Generate pocketbase types | |
runs-on: ubuntu-latest | |
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: 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 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
if [ $(git status --porcelain | wc -l ) -gt 0 ]; then | |
# If there is a diff: https://stackoverflow.com/a/62213712 | |
git checkout -b "$branch" | |
git add --force src/lib/pocketbase/index.d.ts | |
git commit -m "chore: update pocketbase types" | |
git push origin "$branch" | |
gh pr create --base "main" \ | |
--head "$branch" \ | |
--title "Update pocketbase types" \ | |
--body "Updated at $(date -Iminutes)" \ | |
--label "typegen" | |
fi |