-
Notifications
You must be signed in to change notification settings - Fork 270
148 lines (143 loc) Β· 5.89 KB
/
Copy pathwebsite.yml
File metadata and controls
148 lines (143 loc) Β· 5.89 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
145
146
147
148
# 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: Build Attic site
# If the target branch is main, output is written to asf-site and cwiki-retired
# Otherwise, output site is written to $branch-site branch that is staged to https://attic-$branch.staged.apache.org/ for review
on:
push:
# only build main on push. This is to avoid double builds on PRs and consequent failures.
branches:
- main
pull_request:
workflow_dispatch:
jobs:
website:
runs-on: ubuntu-latest
steps:
- name: π Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
- name: π Checkout asf-site branch with minimum depth (main only)
if: ${{ (github.head_ref || github.ref_name) == 'main' }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
with:
ref: asf-site
fetch-depth: 1
path: asf-site
- name: π Checkout cwiki-retired branch with minimum depth (main only)
if: ${{ (github.head_ref || github.ref_name) == 'main' }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
with:
ref: cwiki-retired
fetch-depth: 1
path: cwiki-retired
- name: Set up Ruby
# Although ubuntu-latest includes ruby 3.2.2, this step is needed to set up bundler
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.3
bundler-cache: true
- name: π§ Build site
run: |
rm -rf asf-site/output/*
rm -rf cwiki-retired/*
ruby --version
bundle exec jekyll build -d asf-site/output
- name: Move cwiki-retired out of asf-site (main only)
if: ${{ (github.head_ref || github.ref_name) == 'main' }}
run: |
mv asf-site/output/cwiki_retired/* cwiki-retired
rm -rf asf-site/output/cwiki_retired
- name: π Add commit to the asf-site branch (main only)
if: ${{ (github.head_ref || github.ref_name) == 'main' }}
working-directory: asf-site
run: |
echo "Running git config"
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
echo "Running git add -A"
git add -A .
echo "Running git commit"
if git commit -m "Regenerated website based on ${GITHUB_SHA} commit"
then
git push origin asf-site
fi
- name: π Add commit to the cwiki-retired branch (main only)
if: ${{ (github.head_ref || github.ref_name) == 'main' }}
working-directory: cwiki-retired
run: |
echo "Running git config"
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
echo "Running git add -A"
git add -A .
echo "Running git commit"
if git commit -m "Regenerated cwiki flags based on ${GITHUB_SHA} commit"
then
git push origin cwiki-retired
fi
- name: π Add commit to the site staging *-site branch (except main)
if: ${{ (github.head_ref || github.ref_name) != 'main' }}
run: |
BRANCH="${{ (github.head_ref || github.ref_name) }}"
SITE="${{ (github.head_ref || github.ref_name) }}-site"
# cannot create dependabot/ branches; also '/' is not allowed in the SITE branch name
if [[ $BRANCH == dependabot/* ]]
then
echo "Dependabot cannot create the branch - skipping"
exit 0
# SITE="${SITE//\//-}"
# echo "branch: $BRANCH => site: $SITE = https://attic-${BRANCH//\//-}.staged.apache.org/"
else
echo "branch: $BRANCH => site: $SITE = https://attic-$BRANCH.staged.apache.org/"
fi
echo "Running git config"
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
# ensure access to existing branches (i.e. allow for depth=1)
git fetch --tags -- origin +refs/heads/*:refs/remotes/origin/*
if git switch $SITE
then
echo "updating existing $SITE"
else
echo "creating orphan $SITE"
git switch --orphan $SITE
# Need gitignore
git checkout origin/${BRANCH} -- .gitignore
# create staging site
{
echo "staging:"
echo " profile: $BRANCH"
echo " whoami: $SITE"
} >.asf.yaml
echo "https://attic-$BRANCH.staged.apache.org/\n\nbuilt from \`$BRANCH\` branch https://github.com/apache/attic/tree/$BRANCH" > README.md
git add -A .
git commit -m "Init staging site $SITE"
git push --set-upstream origin $SITE
fi
rm -rf output
mv asf-site/output .
git add -f output # override .gitignore
rm -rf asf-site
echo "Running git add -A"
git add -A .
echo "Running git commit"
if git commit -m "Regenerated website based on ${GITHUB_SHA} commit"
then
git push
fi