forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (60 loc) · 2.06 KB
/
sync-from-upstream.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
name: Sync repository from upstream
on:
workflow_dispatch: {}
schedule:
- cron: 5 2 * * *
env:
BRANCHES: main v2-release
jobs:
# Check for the presence of a PROJEN_GITHUB_TOKEN secret.
#
# This is expected to contain a personal access token of someone who has
# permissions to bypass branch protection rules.
#
# If not present, we can only use GitHub Actions Token permissions,
# but this has the following downsides:
#
# - Those are bound by branch protection rules (so automated pushing won't work).
# - As soon as a workflow file needs to be changed, GitHub will reject the push.
# Only Apps and Users can be allowed to modify workflows.
check-secret:
# Don't run on the target repo itself, only forks
if: github.repository != 'aws/aws-cdk'
runs-on: ubuntu-latest
steps:
- name: Check for presence of PROJEN_GITHUB_TOKEN
id: check-secrets
run: |
if [ ! -z "${{ secrets.PROJEN_GITHUB_TOKEN }}" ]; then
echo "ok=true" >> $GITHUB_OUTPUT
else
echo "ok=false" >> $GITHUB_OUTPUT
fi
outputs:
ok: ${{ steps.check-secrets.outputs.ok }}
sync-branch:
runs-on: ubuntu-latest
permissions:
contents: write
needs: [check-secret]
steps:
- name: Checkout using User Token (+ download lfs dependencies)
if: needs.check-secret.outputs.ok == 'true'
uses: actions/checkout@v4
with:
lfs: true
token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
- name: Checkout using GitHub Actions permissions (+ download lfs dependencies)
if: needs.check-secret.outputs.ok == 'false'
uses: actions/checkout@v4
with:
lfs: true
- name: Checkout LFS objects
run: git lfs checkout
- name: Sync from aws/aws-cdk
run: |-
git remote add upstream https://github.com/aws/aws-cdk.git
git fetch upstream $BRANCHES
for branch in $BRANCHES; do
git push origin --force refs/remotes/upstream/$branch:refs/heads/$branch
done