-
Notifications
You must be signed in to change notification settings - Fork 3
72 lines (67 loc) · 2.3 KB
/
refresh-channels.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Refresh Channels
on:
workflow_dispatch:
inputs:
target_branch:
description: 'Target branch to update channels'
required: true
type: choice
options:
- 'main'
- 'v1.6'
- 'v1.7'
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', 'v1.7']" >> $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 "do-not-use@elemental.suse.com"
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