Skip to content

Refresh Channels

Refresh Channels #185

name: Refresh Channels
on:
workflow_dispatch:
inputs:
target_branch:
description: 'Target branch to update channels'
required: true
type: choice
options:
- 'main'
- 'v1.6'
schedule:
- cron: '0 0 * * *'
jobs:
set-matrix:
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.branches.outputs.branches }}
steps:
- name: Sets the branches to update
id: branches
run: |
if [ "${{ github.event_name }}" != 'workflow_dispatch' ]; then
echo "branches=['main', 'v1.6']" >> $GITHUB_OUTPUT
else
echo "branches=['${{ inputs.target_branch }}']" >> $GITHUB_OUTPUT
fi
refresh-channels:
needs:
- set-matrix
runs-on: ubuntu-latest
strategy:
matrix:
branch: ${{ fromJSON(needs.set-matrix.outputs.branches) }}
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
fetch-depth: 0
- name: Run refresh script
run: ./refresh_channels.sh
- name: Open or refresh PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REFRESH_BRANCH: gha-automated-refresh-${{ matrix.branch }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action Runner"
git switch --force-create "${{ env.REFRESH_BRANCH }}" origin/${{ matrix.branch }}
git add .
if git diff-index --quiet HEAD; then
echo "No new updates. Nothing to do."
exit 0
fi
message="Automatic update. Run ID ${{ github.run_id }}, Number ${{ github.run_number}}, Attempt ${{ github.run_attempt }}"
git commit -m "${message}"
git push --force origin "${{ env.REFRESH_BRANCH }}"
PR_URL="$(gh pr list --head "${{ env.REFRESH_BRANCH }}" --base "${{ matrix.branch }}" --state open --json url --jq .[].url)"
if [[ -n "${PR_URL}" ]]; then
echo "PR already exists -> ${PR_URL}"
gh pr edit "${PR_URL}" --title "${message}"
else
gh pr create --fill --head "${{ env.REFRESH_BRANCH }}" --base "${{ matrix.branch }}"
fi