-
Notifications
You must be signed in to change notification settings - Fork 9
112 lines (104 loc) · 4.03 KB
/
auto-updates.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Auto update broker variant branches
on:
push:
branches:
- main
workflow_dispatch:
concurrency: auto-update-broker-variants
permissions:
pull-requests: write
contents: write
env:
DEBIAN_FRONTEND: noninteractive
jobs:
update-snap-branches:
name: Update snap branches
strategy:
matrix:
branch_name: ["msentraid"]
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
set -eu
sudo apt update
sudo apt install -y git
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Merge main into branches
id: merge
run: |
set -eux
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch
git checkout ${{ matrix.branch_name }}
# First, assume that we will have conflicts due to the merge command
# failing the action if there's any.
echo "has_conflicts=true" >> $GITHUB_OUTPUT
has_conflicts=true
if git merge main --commit; then
has_conflicts=false
fi
echo "has_conflicts=${has_conflicts}" >> $GITHUB_OUTPUT
- uses: actions/setup-go@v5
if: ${{ steps.merge.outputs.has_conflicts == 'false' }}
with:
go-version-file: go.mod
- name: Regenerate consts for this broker
if: ${{ steps.merge.outputs.has_conflicts == 'false' }}
run: |
set -eux
# Regenerate the consts for the broker
go generate ./internal/consts/
- name: Find generated changes
if: ${{ steps.merge.outputs.has_conflicts == 'false' }}
id: check-diff
uses: canonical/desktop-engineering/gh-actions/common/has-diff@main
with:
working-directory: ./internal/consts/
fail-on-diff: false
- name: Commit generated changes
if: ${{ steps.merge.outputs.has_conflicts == 'false' && steps.check-diff.outputs.diff == 'true' }}
run: |
set -eux
git add ./internal/consts/
git commit -m "Regenerate consts for ${{ matrix.branch_name }}"
- name: Create Pull Request
if: ${{ steps.merge.outputs.has_conflicts == 'false' }}
uses: peter-evans/create-pull-request@v7
with:
commit-message: Auto update ${{ matrix.branch_name }} branch
title: Auto update ${{ matrix.branch_name }} branch
body: |
Automated merge from main of ${{ matrix.branch_name }}.
branch: update-${{ matrix.branch_name }}
delete-branch: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Push branch
if: ${{ steps.merge.outputs.has_conflicts == 'false' }}
run: |
set -eux
git push origin update-${{ matrix.branch_name }}:${{ matrix.branch_name }}
- name: Restore and prepare branch
if: ${{ steps.merge.outputs.has_conflicts == 'true' }}
run: |
set -eux
# Reset the state of the current destination
git merge --abort
# Apply the changes we want to merge (which is the content of main)
git reset --hard main
- name: Create Pull Request
if: ${{ steps.merge.outputs.has_conflicts == 'true' }}
uses: peter-evans/create-pull-request@v7
with:
commit-message: Auto update ${{ matrix.branch_name }} branch
title: Auto update ${{ matrix.branch_name }} branch
body: |
Pull request created due to conflicts found when merging main into ${{ matrix.branch_name }}.
Remember to run go generate ./internal/consts/ and committing those changes before merging this PR.
branch: update-${{ matrix.branch_name }}
delete-branch: true
token: ${{ secrets.GITHUB_TOKEN }}