-
Notifications
You must be signed in to change notification settings - Fork 12
152 lines (134 loc) · 4.37 KB
/
Copy pathbuild-vitepress-docs.yml
File metadata and controls
152 lines (134 loc) · 4.37 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
149
150
151
152
name: Build VitePress Docs and Push to Harbor
on:
push:
branches:
- master
- main
- develop
paths:
- 'docs/**'
- '.github/workflows/build-vitepress-docs.yml'
release:
types: [published]
workflow_dispatch:
inputs:
image_tag:
description: 'Docker image tag (default: latest)'
required: false
default: 'latest'
env:
HARBOR_REGISTRY: harbor.1cdevelopers.ru
HARBOR_PROJECT: library
IMAGE_NAME: integration-subsystem-docs
jobs:
build:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.meta.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: docs/package-lock.json
- name: Install dependencies
working-directory: docs
run: npm ci
- name: Build VitePress documentation
working-directory: docs
run: npm run docs:build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: vitepress-dist
path: docs/.vitepress/dist
retention-days: 7
docker:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: vitepress-dist
path: docs/.vitepress/dist
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor Registry
uses: docker/login-action@v3
with:
registry: ${{ env.HARBOR_REGISTRY }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
type=raw,value=${{ github.event.inputs.image_tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
type=sha,prefix=,format=short
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./docs
file: ./docs/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_DATE=${{ github.event.repository.updated_at }}
VCS_REF=${{ github.sha }}
- name: Generate SBOM
uses: anchore/sbom-action@v0
with:
image: ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
format: spdx-json
output-file: sbom.spdx.json
- name: Upload SBOM artifact
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.spdx.json
retention-days: 30
trigger-deployment:
needs: docker
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- name: Trigger ArgoCD deployment update
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.K8S_APPS_PAT }}
repository: segate-k8s/integration-subsystem-docs
event-type: image-updated
client-payload: '{"sha": "${{ github.sha }}", "image_tag": "latest"}'
notify:
needs: [build, docker]
runs-on: ubuntu-latest
if: always()
steps:
- name: Notify on success
if: ${{ needs.docker.result == 'success' }}
run: |
echo "✅ Documentation successfully built and pushed to Harbor"
echo "Image: ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.IMAGE_NAME }}"
- name: Notify on failure
if: ${{ needs.docker.result == 'failure' }}
run: |
echo "❌ Failed to build or push documentation"
exit 1