forked from intersystems-community/vscode-objectscript
-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (125 loc) · 5.22 KB
/
Copy pathsync-upstream.yml
File metadata and controls
144 lines (125 loc) · 5.22 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Sync upstream (daily)
on:
schedule:
# GitHub cron é UTC.
# 03:00 UTC ≈ 00:00 America/Sao_Paulo.
- cron: "0 3 * * *"
workflow_dispatch: {}
permissions:
contents: write
pull-requests: write
concurrency:
group: sync-upstream
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
env:
UPSTREAM_REPO: intersystems-community/vscode-objectscript
UPSTREAM_BRANCH: master
BASE_BRANCH: master
SYNC_BRANCH: bot/sync-upstream-master
steps:
- name: Checkout base
uses: actions/checkout@v4
with:
ref: ${{ env.BASE_BRANCH }}
fetch-depth: 0
token: ${{ github.token }}
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Add upstream and fetch
run: |
set -euo pipefail
git remote add upstream https://github.com/${UPSTREAM_REPO}.git
git fetch upstream --prune
- name: Check if Chat webhook is configured
id: chat
env:
CHAT_WEBHOOK: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}
run: |
if [ -n "${CHAT_WEBHOOK}" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Check if upstream has new commits
id: diff
run: |
set -euo pipefail
BASE_SHA="$(git rev-parse HEAD)"
UP_SHA="$(git rev-parse upstream/${UPSTREAM_BRANCH})"
echo "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
echo "upstream_sha=$UP_SHA" >> "$GITHUB_OUTPUT"
# Só precisa sync quando o topo do upstream ainda NÃO está contido na base.
if git merge-base --is-ancestor "upstream/${UPSTREAM_BRANCH}" "$BASE_SHA"; then
echo "needs_update=false" >> "$GITHUB_OUTPUT"
else
echo "needs_update=true" >> "$GITHUB_OUTPUT"
fi
- name: Stop if no updates
if: steps.diff.outputs.needs_update != 'true'
run: echo "No updates. Nothing to do."
- name: Attempt merge upstream into working tree (merge commit)
if: steps.diff.outputs.needs_update == 'true'
id: merge_result
run: |
set -euo pipefail
git checkout "${BASE_BRANCH}"
# Força merge commit quando possível, sem push direto na base.
if git merge --no-ff --no-edit "upstream/${UPSTREAM_BRANCH}"; then
echo "merged=true" >> "$GITHUB_OUTPUT"
else
git merge --abort || true
echo "merged=false" >> "$GITHUB_OUTPUT"
fi
- name: Create or update PR
if: steps.diff.outputs.needs_update == 'true' && steps.merge_result.outputs.merged == 'true'
id: pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ github.token }}
branch: ${{ env.SYNC_BRANCH }}
base: ${{ env.BASE_BRANCH }}
title: "chore(sync): merge upstream/${{ env.UPSTREAM_BRANCH }} into ${{ env.BASE_BRANCH }}"
body: |
Atualização automática do fork com mudanças do upstream.
commit-message: "chore(ci): sync upstream/${{ env.UPSTREAM_BRANCH }}"
delete-branch: false
- name: Notify Google Chat (success)
if: steps.chat.outputs.enabled == 'true' && steps.diff.outputs.needs_update == 'true' && steps.merge_result.outputs.merged == 'true' && steps.pr.outputs.pull-request-url != ''
env:
WEBHOOK: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}
MSG: |
✅ PR de sync com upstream criado/atualizado
Repositório: ${{ github.repository }}
PR: ${{ steps.pr.outputs.pull-request-url }}
Status: aguardando merge manual do PR
Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
curl -sS -X POST "$WEBHOOK" \
-H 'Content-Type: application/json' \
-d "$(python3 -c 'import json, os; print(json.dumps({"text": os.environ["MSG"]}))')"
- name: Notify Google Chat (conflict)
if: steps.chat.outputs.enabled == 'true' && steps.diff.outputs.needs_update == 'true' && steps.merge_result.outputs.merged != 'true'
env:
WEBHOOK: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}
MSG: |
⚠️ Sync do upstream com conflito
Repositório: ${{ github.repository }}
Branch de sync: ${{ env.SYNC_BRANCH }}
Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Resolver manualmente:
1) git fetch upstream
2) git checkout ${{ env.SYNC_BRANCH }}
3) git merge upstream/${{ env.UPSTREAM_BRANCH }}
4) resolver conflitos
5) git add .
6) git commit -m "chore(sync): resolve upstream merge conflicts"
7) git push origin ${{ env.SYNC_BRANCH }}
run: |
curl -sS -X POST "$WEBHOOK" \
-H 'Content-Type: application/json' \
-d "$(python3 -c 'import json, os; print(json.dumps({"text": os.environ["MSG"]}))')"