Skip to content

update-templates

update-templates #15

name: Update Templates
on:
workflow_dispatch:
inputs:
base_image:
description: 'Base image to update'
required: true
type: string
module_version:
description: 'Playwright or Puppeteer version'
required: false
type: string
default_runtime_version:
description: 'Default runtime version (example: 24 for node, 3.13 for python)'
required: false
type: string
repository_dispatch:
types:
- update-templates
env:
BASE_IMAGE_RAW: ${{ github.event.client_payload.base_image || inputs.base_image }}
RAW_BRANCH_NAME: ci/${{ github.event.client_payload.base_image || inputs.base_image }}
BASE_IMAGE: ${{ github.event.client_payload.base_image || inputs.base_image }}
DEFAULT_RUNTIME_VERSION: ${{ github.event.client_payload.default_runtime_version || inputs.default_runtime_version }}
MODULE_VERSION: ${{ github.event.client_payload.module_version || inputs.module_version }}
jobs:
update-templates:
runs-on: ubuntu-latest
steps:
- name: Sanitize base image
id: branch-name
run: |
echo "BRANCH_NAME=$(echo '${{ env.RAW_BRANCH_NAME }}' | sed 's/,/_/g')" >> $GITHUB_OUTPUT
echo "BASE_IMAGE_FORMATTED=$(echo '${{ env.BASE_IMAGE_RAW }}' | sed 's/,/, /g')" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Check and manage branch
run: |
# Fetch all branches
git fetch origin
# Check if branch exists on remote
if git ls-remote --heads origin "${{ steps.branch-name.outputs.BRANCH_NAME }}" | grep -q "${{ steps.branch-name.outputs.BRANCH_NAME }}"; then
echo "Branch ${{ steps.branch-name.outputs.BRANCH_NAME }} exists, checking it out and resetting to origin/master"
git checkout "${{ steps.branch-name.outputs.BRANCH_NAME }}"
git reset --hard origin/master
else
echo "Branch ${{ steps.branch-name.outputs.BRANCH_NAME }} does not exist, creating it"
git checkout -b "${{ steps.branch-name.outputs.BRANCH_NAME }}"
fi
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Run update script
env:
BASE_IMAGE: ${{ env.BASE_IMAGE_RAW }}
DEFAULT_RUNTIME_VERSION: ${{ env.DEFAULT_RUNTIME_VERSION }}
MODULE_VERSION: ${{ env.MODULE_VERSION }}
run: node ./scripts/actions/update-templates.mts
- name: Commit and push changes
id: commit-and-push
run: |
# Check if there are any changes
if git diff --quiet && git diff --cached --quiet; then
echo "No changes to commit"
else
git add -A
git commit -m "chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}"
echo "committed=true" >> $GITHUB_OUTPUT
fi
# Force push the branch
git push --force origin "${{ steps.branch-name.outputs.BRANCH_NAME }}"
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
if: steps.commit-and-push.outputs.committed == 'true'
run: |
# Check if PR already exists
PR_EXISTS=$(gh pr list --head "${{ steps.branch-name.outputs.BRANCH_NAME }}" --base master --json number --jq length)
if [ "$PR_EXISTS" -eq "0" ]; then
echo "Creating new PR"
gh pr create \
--title "chore: Update templates for base image: ${{ steps.branch-name.outputs.BASE_IMAGE_FORMATTED }}" \
--body "Automated update of templates for base image \`${{ steps.branch-name.outputs.BASE_IMAGE_FORMATTED }}\`
**Parameters:**
- Base Image: \`${{ steps.branch-name.outputs.BASE_IMAGE_FORMATTED }}\`
- Runtime Version: \`${{ env.DEFAULT_RUNTIME_VERSION }}\`
- Module Version: \`${{ env.MODULE_VERSION || 'N/A' }}\`
> Generated by [Update Templates](https://github.com/apify/actor-templates/actions/workflows/update-templates.yml) workflow." \
--base master \
--head "${{ steps.branch-name.outputs.BRANCH_NAME }}" \
--reviewer B4nan \
--reviewer vladfrangu
else
echo "PR already exists for branch ${{ steps.branch-name.outputs.BRANCH_NAME }}, updating it"
# gh pr edit supports a branch name or a PR number or a URL
gh pr edit "${{ steps.branch-name.outputs.BRANCH_NAME }}" \
--body "Automated update of templates for base image \`${{ steps.branch-name.outputs.BASE_IMAGE_FORMATTED }}\`
**Parameters:**
- Base Image: \`${{ steps.branch-name.outputs.BASE_IMAGE_FORMATTED }}\`
- Runtime Version: \`${{ env.DEFAULT_RUNTIME_VERSION }}\`
- Module Version: \`${{ env.MODULE_VERSION || 'N/A' }}\`
> Generated by [Update Templates](https://github.com/apify/actor-templates/actions/workflows/update-templates.yml) workflow."
fi