-
Notifications
You must be signed in to change notification settings - Fork 29
82 lines (79 loc) · 2.98 KB
/
copy-headers.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
# heavily inspired by https://www.paigeniedringhaus.com/blog/copy-files-from-one-repo-to-another-automatically-with-git-hub-actions
name: Copy headers to separate repo
on:
push:
pull_request_target:
types: [opened, synchronize]
permissions:
contents: read
pull-requests: read
jobs:
copy_headers:
if: github.repository == 'MonsterDruide1/OdysseyDecomp'
runs-on: ubuntu-latest
steps:
- name: Check out OdysseyDecomp project
uses: actions/checkout@v4
with:
submodules: recursive
- name: Check out branch if in PR
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive
- name: Check out OdysseyHeaders project
uses: actions/checkout@v4
with:
repository: MonsterDruide1/OdysseyHeaders
path: ./OdysseyHeaders
token: ${{ secrets.HEADERS_TOKEN }}
- name: Create proper branch name (for PRs, in Headers repo)
run: |
if [[ $GITHUB_EVENT_NAME == 'pull_request_target' ]]
then
echo "HEADER_BRANCH=pr-$PR_NUM" >> "$GITHUB_ENV"
if [[ $PR_AUTHOR_NAME != '' ]]
then
echo "AUTHOR_NAME=$PR_AUTHOR_NAME" >> "$GITHUB_ENV"
else
echo "AUTHOR_NAME=$PR_AUTHOR_LOGIN" >> "$GITHUB_ENV"
fi
if [[ $PR_AUTHOR_MAIL != '' ]]
then
echo "AUTHOR_MAIL=$PR_AUTHOR_MAIL"
else
echo "[email protected]" >> "$GITHUB_ENV"
fi
echo "MESSAGE=$PR_TITLE" >> "$GITHUB_ENV"
else
echo "HEADER_BRANCH=${DELETED_BRANCH#refs/heads/}" >> "$GITHUB_ENV"
echo "AUTHOR_NAME=$COMMIT_AUTHOR_NAME" >> "$GITHUB_ENV"
echo "AUTHOR_MAIL=$COMMIT_AUTHOR_MAIL" >> "$GITHUB_ENV"
{
echo 'MESSAGE<<EOF'
echo $COMMIT_MESSAGE
echo EOF
} >> "$GITHUB_ENV"
fi
env:
DELETED_BRANCH: ${{ github.event.ref }}
PR_NUM: ${{ github.event.pull_request.number }}
COMMIT_AUTHOR_NAME: ${{ github.event.commits[0].author.name }}
COMMIT_AUTHOR_MAIL: ${{ github.event.commits[0].author.email }}
COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
PR_AUTHOR_NAME: ${{ github.event.pull_request.user.name }}
PR_AUTHOR_LOGIN: ${{ github.event.pull_request.user.login }}
PR_AUTHOR_MAIL: ${{ github.event.pull_request.user.email }}
PR_TITLE: ${{ github.event.pull_request.title }}
- name: Move to correct branch of OdysseyHeaders and reset history
run: |
cd OdysseyHeaders
git checkout $HEADER_BRANCH 2>/dev/null || git checkout -b $HEADER_BRANCH
git reset --hard origin/master
- name: Copy files
run: bash ./.github/scripts/copy-headers.sh
env:
DESTINATION_PATH: ./OdysseyHeaders
- name: Push to OdysseyHeaders repo
run: bash ./.github/scripts/push-headers.sh