-
Notifications
You must be signed in to change notification settings - Fork 11
179 lines (163 loc) · 5.33 KB
/
build-and-release.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Build and Release
on:
workflow_dispatch:
branches: [main]
push:
branches: [main]
tags: ['v*']
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install packages
run: |
git config --global url."https://${{ secrets.MKDOCS_INSIDERS_TOKEN }}@github".insteadOf https://github
pip install git+https://github.com/squidfunk/mkdocs-material-insiders.git mkdocs-redirects
- name: Build
run: make build
env:
SITE_OUTPUT_DIR: /tmp/output/site
- name: Upload artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@master
with:
name: site
path: /tmp/output/site
publish-image:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install packages
run: |
git config --global url."https://${{ secrets.MKDOCS_INSIDERS_TOKEN }}@github".insteadOf https://github
pip install git+https://github.com/squidfunk/mkdocs-material-insiders.git mkdocs-redirects mike
- name: Configure git credentials
run: |
git config --global user.name 'TriggerMesh Bot'
git config --global user.email '[email protected]'
- name: Configure DOCS_VERSION
id: docs-version
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
DOCS_VERSION=${GITHUB_REF_NAME:1}
DOCS_VERSION=${DOCS_VERSION%.*}
fi
echo "DOCS_VERSION=${DOCS_VERSION:-DEV}" >> $GITHUB_OUTPUT
- name: Deploy version and push
run: |
DOCS_VERSION="${{ steps.docs-version.outputs.DOCS_VERSION }}"
if [[ "${DOCS_VERSION}" != "DEV" ]]; then
mike deploy ${DOCS_VERSION} latest --update-aliases --push
else
mike deploy ${DOCS_VERSION}
fi
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to GCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCLOUD_SERVICEACCOUNT_KEY }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: gcr.io/triggermesh/docs
tags: |
type=semver,pattern={{raw}}
type=sha
- name: Switch to gh-pages branch
run: git checkout gh-pages
- name: Build and push image
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
update-config:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' }}
needs: publish-image
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout triggermesh/docs
uses: actions/checkout@v3
with:
path: 'tm-config'
ref: 'main'
repository: 'triggermesh/config'
token: ${{ secrets.BOT_TOKEN }}
- name: Set IMAGE_TAG
id: image-tag
run: |
IMAGE_TAG=sha-${GITHUB_SHA:0:7}
[[ ${GITHUB_REF_TYPE} == "tag" ]] && IMAGE_TAG=${GITHUB_REF_NAME}
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Update config
working-directory: tm-config
run: |
sed -i overlays/staging/docs-staging/deployment.yaml -e "s|gcr.io/triggermesh/docs:.*|gcr.io/triggermesh/docs:"${{ steps.image-tag.outputs.IMAGE_TAG }}"|g"
if [[ ${{ steps.image-tag.outputs.IMAGE_TAG }} =~ ^v([0-9]{1,}\.){2}[0-9]{1,}$ ]]; then
sed -i overlays/staging/docs/deployment.yaml -e "s|gcr.io/triggermesh/docs:.*|gcr.io/triggermesh/docs:"${{ steps.image-tag.outputs.IMAGE_TAG }}"|g"
fi
git --no-pager diff
- name: Commit and push changes
working-directory: tm-config
run: |
git add -A
git status --porcelain
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
git config --global user.name 'TriggerMesh Bot'
git config --global user.email '[email protected]'
git commit -m "Update docs deployment to 'gcr.io/triggermesh/docs:${{ steps.image-tag.outputs.IMAGE_TAG }}'"
git push
fi
create-release:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: publish-image
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@master
with:
name: site
path: /tmp/output/site
- name: Build release package
env:
DIST_DIR: /tmp/dist
SITE_OUTPUT_DIR: /tmp/output/site
run: make release
- name: Preparing Release Notes
run: |
./scripts/release-notes.sh ${GITHUB_REF_NAME} > release-notes.md
- name: Creating Release
uses: ncipollo/release-action@v1
with:
bodyFile: "release-notes.md"
artifacts: "/tmp/dist/*"