🏡 index : quine-global-labs/mirror-coreos-fedora-coreos-config.git

name: Sync to coreos/rhel-coreos-config
on:
  # We could do push: branches: [testing-devel] but that would restart
  # downstream CI a lot
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:
    inputs:
      branch:
        # Allow specifying the source branch for backports
        description: Source branch to use for PR
        required: true
        default: testing-devel
        type: choice
        options:
          - testing-devel
          - rhel-9.6
          - rhcos-4.18
          - rhcos-4.17
          - rhcos-4.16
          - rhcos-4.15
          - rhcos-4.14
          - rhcos-4.13
          - rhcos-4.12
          - rhcos-4.11
          - rhcos-4.10
      jira:
        description: The JIRA reference to put in the PR title. Defaults to "NO-JIRA".
        required: false
        default: NO-JIRA
        type: string

permissions:
  # none at all
  contents: none

jobs:
  update-submodule:
    name: Update fedora-coreos-config submodule
    runs-on: ubuntu-latest
    env:
      SOURCE_BRANCH: ${{ github.event.inputs.branch }}
      JIRA: ${{ github.event.inputs.jira }}
    steps:
      - name: Set branches values
        run: |
          set -euxo pipefail

          case $SOURCE_BRANCH in
              # in the on.schedule case, the SOURCE_BRANCH is empty
              testing-devel|"")
                TARGET_REPO=coreos/rhel-coreos-config
                echo "SOURCE_BRANCH=testing-devel" >> $GITHUB_ENV
                echo "TARGET_BRANCH=main" >> $GITHUB_ENV
                echo "BRANCH_NAME=fcc-sync" >> $GITHUB_ENV
                ;;
              rhcos-*)
                TARGET_REPO=openshift/os
                # split the string around the -
                array=(${SOURCE_BRANCH//-/ })
                OCP_VERSION=${array[1]}
                echo "TARGET_BRANCH=release-${OCP_VERSION}" >> $GITHUB_ENV
                echo "BRANCH_NAME=fcc-sync-${SOURCE_BRANCH}" >> $GITHUB_ENV
                echo "TITLE_PREFIX=[release-${OCP_VERSION}] " >> $GITHUB_ENV
                ;;
              rhel-*)
                TARGET_REPO=coreos/rhel-coreos-config
                echo "TARGET_BRANCH=${SOURCE_BRANCH}" >> $GITHUB_ENV
                echo "BRANCH_NAME=fcc-sync-${SOURCE_BRANCH}" >> $GITHUB_ENV
                echo "TITLE_PREFIX=[${SOURCE_BRANCH}] " >> $GITHUB_ENV
                ;;
              *)
                echo "SOURCE_BRANCH=$SOURCE_BRANCH is invalid" >&2
                exit 1
                ;;
          esac

          echo "TARGET_REPO=${TARGET_REPO}" >> $GITHUB_ENV
          echo "TARGET_REPO_NAME=${TARGET_REPO#*/}" >> $GITHUB_ENV
          echo "JIRA=${JIRA:-NO-JIRA}" >> $GITHUB_ENV
      - name: Check out repository
        uses: actions/checkout@v3
        with:
          repository: ${{ env.TARGET_REPO }}
          # We need an unbroken commit chain when pushing to the fork.  Don't
          # make assumptions about which commits are already available there.
          fetch-depth: 0
          # We need to checkout against the target branch
          ref: ${{ env.TARGET_BRANCH }}

      - name: Update submodule
        run: |
          set -euxo pipefail

          git submodule init
          git submodule update

          cd fedora-coreos-config
          # the submodule init only fetch the submodule commit and the default branch `testing-devel`
          git fetch origin ${SOURCE_BRANCH}
          # Omit CoreOS Bot commits from the log message, since they generally
          # only affect FCOS
          git shortlog "HEAD..FETCH_HEAD" --perl-regexp \
              --author='^((?!CoreOS Bot <coreosbot@fedoraproject.org>).*)$' \
              > $RUNNER_TEMP/shortlog

          if [ ! -s $RUNNER_TEMP/shortlog ]; then
              # Any changes have been made by CoreOS Bot.  Ignore.
              echo "No non-trivial changes; exiting"
              exit 0
          fi

          git checkout $SOURCE_BRANCH

          marker=END-OF-LOG-MARKER-$RANDOM$RANDOM$RANDOM
          cat >> $GITHUB_ENV <<EOF
          SHORTLOG<<$marker
          $(cat $RUNNER_TEMP/shortlog)
          $marker
          EOF

      - name: Open pull request
        uses: peter-evans/create-pull-request@v8
        with:
          token: ${{ secrets.COREOSBOT_RELENG_TOKEN }}
          push-to-fork: coreosbot-releng/${{ env.TARGET_REPO_NAME }}
          branch: ${{ env.BRANCH_NAME }}
          base: ${{ env.TARGET_BRANCH }}
          commit-message: |
            Bump fedora-coreos-config

            ${{ env.SHORTLOG }}
          title: "${{ env.TITLE_PREFIX }}${{ env.JIRA }}: Bump fedora-coreos-config"
          body: |
            Created by [GitHub workflow](${{ github.server_url }}/${{ github.repository }}/actions/workflows/bump-rhcos-submodule.yml) ([source](${{ github.server_url }}/${{ github.repository }}/blob/testing-devel/.github/workflows/bump-rhcos-submodule.yml)).

            ```
            ${{ env.SHORTLOG }}
            ```
          committer: "CoreOS Bot <coreosbot@fedoraproject.org>"
          author: "CoreOS Bot <coreosbot@fedoraproject.org>"