nightly #487
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: nightly | |
on: | |
schedule: | |
- cron: '15 1 * * *' | |
workflow_dispatch: | |
jobs: | |
nightly: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 9 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20.x | |
- name: Install dependencies | |
run: pnpm i --frozen-lockfile | |
- name: Generate types | |
run: pnpm generate ${{ secrets.GITHUB_TOKEN }} | |
- name: Check git status | |
id: status | |
run: | | |
if [[ -n "$(git status --porcelain)" ]]; then | |
echo "changes=true" >> $GITHUB_OUTPUT | |
else | |
echo "changes=false" >> $GITHUB_OUTPUT | |
fi | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Configure git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Set timestamp | |
run: | | |
raw_timestamp=$(date +"%Y%m%d-%H%M%S") | |
timestamp=${raw_timestamp//[^a-zA-Z0-9]/-} | |
echo "timestamp=$timestamp" >> "$GITHUB_ENV" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Get latest commit hash from bigcommerce/docs | |
run: | | |
gh_response=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/bigcommerce/docs/commits?per_page=1") | |
most_recent_commit=$(echo "$gh_response" | jq -r '.[0].sha') | |
most_recent_commit_short=${most_recent_commit:0:7} | |
echo "sha=$most_recent_commit_short" >> "$GITHUB_ENV" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Create branch | |
run: | | |
branch_name="nightly-$timestamp" | |
git checkout -b "$branch_name" | |
echo "branch_name=$branch_name" >> "$GITHUB_ENV" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Stage changes | |
run: git add . | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Commit changes | |
run: | | |
commit_message="[nightly] generate types against bigcommerce/docs@$sha" | |
git commit -m "$commit_message" | |
echo "commit_message=$commit_message" >> "$GITHUB_ENV" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Push changes | |
run: git push --set-upstream origin "$branch_name" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Write PR body | |
run: | | |
body="Types generated via scheduled GitHub Actions job against [bigcommerce/docs@\`$sha\`](https://github.com/bigcommerce/docs/tree/$sha)" | |
echo "pr_body=$body" >> "$GITHUB_ENV" | |
- if: ${{ steps.status.outputs.changes == 'true' }} | |
name: Open PR | |
run: gh pr create --base main --title "$commit_message" --body "$pr_body" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |