# This workflow will update the pinned browsers

name: 'Update the pinned browsers'

permissions: read-all

on:
  schedule:
    # Run everyday at: https://crontab.guru/#0_6_*_*_*.
    - cron: '0 6 * * *'
  workflow_dispatch:

jobs:
  update-chrome:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - name: Set up Node.js
        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          cache: npm
          node-version-file: '.nvmrc'
      - uses: google/wireit@9d7c2e5346f8ef1b1ab6014c4e96c74e234f7ed5 # setup-github-actions-caching/v2.0.4
      - name: Install npm dependencies
        run: npm ci
      - name: Build Puppeteer
        run: npm run build -w puppeteer
      - name: Update Chrome to latest stable version
        id: update
        run: |
          node tools/update_browser_revision.mjs
        env:
          BROWSER_TO_UPDATE: 'chrome'
      - name: Create Pull Request
        if: ${{ steps.update.outputs.commit }}
        uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
        with:
          token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
          branch: browser-automation-bot/update-browser-version-chrome
          delete-branch: true
          committer: Browser Automation Bot <browser-automation-bot@google.com>
          author: Browser Automation Bot <browser-automation-bot@google.com>
          commit-message: ${{ steps.update.outputs.commit }}
          title: ${{ steps.update.outputs.commit }}
          body: 'Automatically generated by https://github.com/puppeteer/puppeteer/blob/main/.github/workflows/update-browser-pins.yml'
          labels: full-ci

  update-firefox:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - name: Set up Node.js
        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          cache: npm
          node-version-file: '.nvmrc'
      - uses: google/wireit@9d7c2e5346f8ef1b1ab6014c4e96c74e234f7ed5 # setup-github-actions-caching/v2.0.4
      - name: Install npm dependencies
        run: npm ci
      - name: Build Puppeteer
        run: npm run build -w puppeteer
      - name: Update Firefox to latest stable version
        id: update
        run: |
          node tools/update_browser_revision.mjs
        env:
          BROWSER_TO_UPDATE: 'firefox'
      - name: Create Pull Request
        if: ${{ steps.update.outputs.commit }}
        uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
        with:
          token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
          branch: browser-automation-bot/update-browser-version-firefox
          delete-branch: true
          committer: Browser Automation Bot <browser-automation-bot@google.com>
          author: Browser Automation Bot <browser-automation-bot@google.com>
          commit-message: ${{ steps.update.outputs.commit }}
          title: ${{ steps.update.outputs.commit }}
          body: 'Automatically generated by https://github.com/puppeteer/puppeteer/blob/main/.github/workflows/update-browser-pins.yml'
          labels: full-ci
