-
Notifications
You must be signed in to change notification settings - Fork 108
145 lines (144 loc) · 5.67 KB
/
deploy.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
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
145
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Deploy
on:
push:
branches:
- main
pull_request:
branches:
- "*"
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout git repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: "npm"
- name: Configure for production
run: |
echo "JEKYLL_BASE_URL=" >> ${GITHUB_ENV}
echo "ORIGIN=${{ github.repository }}" >> ${GITHUB_ENV}
echo "TARGET_BRANCH=asf-site" >> ${GITHUB_ENV}
echo >> _extra_config.yml
if: |
github.event_name == 'push' &&
github.repository == 'apache/arrow-site'
- name: Configure for GitHub Pages on push to main branch
run: |
owner=$(jq --raw-output .repository.owner.login ${GITHUB_EVENT_PATH})
repository=$(jq --raw-output .repository.name ${GITHUB_EVENT_PATH})
echo "JEKYLL_BASE_URL=/${repository}" >> ${GITHUB_ENV}
echo "ORIGIN=${owner}/${repository}" >> ${GITHUB_ENV}
echo "TARGET_BRANCH=gh-pages" >> ${GITHUB_ENV}
# "url:" is for the opengraph tags, and it can't be relative
echo "url: https://${owner}.github.io/${repository}" >> _extra_config.yml
if: |
github.event_name == 'push' &&
github.repository != 'apache/arrow-site'
- name: Configure for GitHub Pages on pull request
run: |
owner=$(jq --raw-output .pull_request.head.user.login ${GITHUB_EVENT_PATH})
repository=$(jq --raw-output .pull_request.head.repo.name ${GITHUB_EVENT_PATH})
echo "JEKYLL_BASE_URL=/${repository}" >> ${GITHUB_ENV}
echo "ORIGIN=${owner}/${repository}" >> ${GITHUB_ENV}
echo "TARGET_BRANCH=gh-pages" >> ${GITHUB_ENV}
# "url:" is for the opengraph tags, and it can't be relative
echo "url: https://${owner}.github.io/${repository}" >> _extra_config.yml
if: |
github.event_name == 'pull_request'
- name: Build
run: |
export JEKYLL_DESTINATION=../build
export JEKYLL_ENV=production
export JEKYLL_EXTRA_CONFIG=_extra_config.yml
bundle exec rake generate
cp -a .asf.yaml ../build/
- name: Deploy
run: |
git config user.name "$(git log -1 --pretty=format:%an)"
git config user.email "$(git log -1 --pretty=format:%ae)"
git remote add deploy \
https://x-access-token:${GITHUB_TOKEN}@github.com/${ORIGIN}.git
git fetch deploy
if ! git checkout --track deploy/${TARGET_BRANCH}; then
git checkout -b ${TARGET_BRANCH} remotes/origin/asf-site
fi
if [ "$ORIGIN" != "apache/arrow-site" ]; then
# Pull latest asf-site (for docs etc.) if we're not already on it
git remote add apache https://github.com/apache/arrow-site.git
git fetch apache
git reset --hard apache/asf-site
PUSH_ARGS="-f"
fi
rsync \
-a \
--delete \
--exclude '/.git/' \
--exclude '/ballista/' \
--exclude '/docs/' \
../build/ \
./
rsync \
-a \
../build/docs/ \
docs/
touch .nojekyll
if [ "$(git status --porcelain)" != "" ]; then
# There are changes to the built site
git add --all
git commit -m "Updating built site (build ${GITHUB_SHA})"
git push ${PUSH_ARGS} deploy ${TARGET_BRANCH}
else
echo "No changes to the built site"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
github.repository == github.event.pull_request.head.repo.full_name)
- name: Comment GitHub Pages URL
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload;
const base_repo = payload.pull_request.base.repo;
const head = payload.pull_request.head;
const head_repo = head.repo;
const github_pages_url =
`https://${head_repo.owner.login}.github.io/${head_repo.name}/`;
const body = `${github_pages_url}\n${head.sha}`;
github.rest.issues.createComment({
"owner": base_repo.owner.login,
"repo": base_repo.name,
"issue_number": payload.number,
"body": body
});
if: |
github.event_name == 'pull_request' &&
github.repository == github.event.pull_request.head.repo.full_name