name: "Update cacert.pem"

on:
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * *' # Midnight - every night

permissions:
  contents: write
  pull-requests: write

jobs:
  update:
    strategy:
      matrix:
        branch: [1.4, main]

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ matrix.branch }}

      - name: Download cacert.pem
        working-directory: res
        run: curl -O https://curl.se/ca/cacert.pem

      - name: Check SHA256SUM
        working-directory: res
        run: |
          curl -O https://curl.se/ca/cacert.pem.sha256
          sha256sum -c cacert.pem.sha256
          rm -f cacert.pem.sha256

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v6
        with:
          title: 'Update cacert.pem'
          body: |
            Update cacert.pem using latest from https://curl.se/docs/caextract.html
          commit-message: Update cacert.pem
          branch: cacert-update/${{ matrix.branch }}
          delete-branch: true
          sign-commits: true
          add-paths: |
            res/cacert.pem
