forked from flexera-public/rightscale-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (114 loc) · 4.46 KB
/
build.yaml
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
name: "Docs - Build"
on:
push:
branches:
- main
tags:
- release*
pull_request:
branches:
- main
permissions:
contents: write
pages: write
env:
# HOME required by Setup Git and Setup Go Steps
HOME: ${{ github.workspace }}
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
strategy:
# Don't fail other services if one is failing.
fail-fast: false
matrix:
index:
- build
- check_links
steps:
# SSH Agent Setup required for git to pull modules from private repos
# - name: SSH Agent Setup
# uses: webfactory/[email protected]
#with:
# ssh-private-key: ${{ secrets.GLOBAL_FLEXERA_CI_PRIVATE_SSH_KEY }}
- name: Checkout so we can get build tags
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive
- name: Setup Environment Variables
env:
GITHUB_REF: ${{ github.ref }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_PR: ${{ github.event_name }}
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
if [[ $GITHUB_REF =~ 'refs/tags' ]];
then
## Get just the git tag from GITHUB_REF
echo GITHUB_TAG=${GITHUB_REF#refs/tags/*} >> $GITHUB_ENV
## Set TRAVIS_TAG and TAG which are used by flexera/go-makefiles submodule and originally based on TravisCI
echo TRAVIS_TAG=${GITHUB_REF#refs/tags/*} >> $GITHUB_ENV
# Also set the branch name for tags
echo TRAVIS_BRANCH=${GITHUB_REF#refs/tags/*} >> $GITHUB_ENV
echo TAG=${GITHUB_REF#refs/tags/*} >> $GITHUB_ENV
elif [[ $GITHUB_REF =~ 'refs/heads' ]];
then
## Get the branch name and set TRAVIS_BRANCH
echo TRAVIS_BRANCH=${GITHUB_REF#refs/heads/*} >> $GITHUB_ENV
echo set TRAVIS_BRANCH to $TRAVIS_BRANCH
elif [[ $GITHUB_PR == 'pull_request' ]];
then
## Get the branch name and set TRAVIS_BRANCH
echo TRAVIS_BRANCH=${PR_BRANCH} >> $GITHUB_ENV
echo set TRAVIS_BRANCH to $TRAVIS_BRANCH
else
echo unknown github ref $GITHUB_REF
fi
- name: Get Pull Request status
run: |
if [ -z "$GITHUB_PULL_REQUEST_STATUS" ]
then
echo TRAVIS_PULL_REQUEST=false >> $GITHUB_ENV
echo set TRAVIS_PULL_REQUEST to $TRAVIS_PULL_REQUEST
else
echo TRAVIS_PULL_REQUEST=$GITHUB_PULL_REQUEST_STATUS >> $GITHUB_ENV
echo set TRAVIS_PULL_REQUEST to $TRAVIS_PULL_REQUEST
fi
env:
GITHUB_PULL_REQUEST_STATUS: ${{ github.event.number }}
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.3.8"
bundler-cache: true
- name: Update git config
run: |
git config --global user.email "Github Actions"
git config --global user.name "Automated Deployment"
git config --global url."[email protected]:".insteadOf "https://github.com"
- name: Script
run: |
# Update rubygems
gem update --system 3.2.3
echo "Pull Request: $TRAVIS_PULL_REQUEST"
# Ensure the site builds, otherwise fail the build on PRs
if [[ $CI_NODE_INDEX = "build" && $TRAVIS_PULL_REQUEST != 'false' ]]; then bundle exec rake download_policy_list; TARGET="test" bundle exec middleman build; fi
# Ensure the links work, otherwise fail the build on PRs (only on PRs)
if [[ $CI_NODE_INDEX = "check_links" && $TRAVIS_PULL_REQUEST != 'false' ]]; then echo "TODO Fix check_links to throttle itself properly"; fi
# Only deploy the site live if the master branch is updated (not during pull-requests)
# Currently, deploy first builds by default
if [[ $CI_NODE_INDEX = "build" && $TRAVIS_PULL_REQUEST == 'false' ]]; then bundle exec rake download_policy_list; bundle exec middleman build; fi
env:
CI_NODE_INDEX: ${{ matrix.index }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to Github Pages
if: ${{env.CI_NODE_INDEX == 'build'}}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
env:
CI_NODE_INDEX: ${{ matrix.index }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}