build: check last pipeline status
- using pipeline badge - https://docs.gitlab.com/ee/ci/pipelines/settings.html#pipeline-status-badge
This commit is contained in:
		
							parent
							
								
									6752281a59
								
							
						
					
					
						commit
						522a8814c4
					
				
							
								
								
									
										12
									
								
								src/build.js
								
								
								
								
							
							
						
						
									
										12
									
								
								src/build.js
								
								
								
								
							|  | @ -3,6 +3,7 @@ | |||
| // for deployment outside of GitLab CI, e.g. Cloudflare Pages and Netlify
 | ||||
| 
 | ||||
| const { stream: gotStream } = require('got') | ||||
| const got = require('got') | ||||
| const unzip = require('extract-zip') | ||||
| const { join } = require('path') | ||||
| const { mkdir } = require('fs/promises') | ||||
|  | @ -14,8 +15,18 @@ const tmpPath = join(rootPath, 'tmp') | |||
| const publicPath = join(rootPath, 'public') | ||||
| const zipPath = join(tmpPath, 'artifacts.zip') | ||||
| const artifactsUrl = 'https://gitlab.com/curben/phishing-filter/-/jobs/artifacts/main/download?job=pages' | ||||
| const pipelineUrl = 'https://gitlab.com/curben/phishing-filter/badges/main/pipeline.svg' | ||||
| const ghMirror = 'https://nightly.link/curbengh/phishing-filter/workflows/pages/main/public.zip' | ||||
| 
 | ||||
| const pipelineStatus = async (url) => { | ||||
|   try { | ||||
|     const svg = await got(url).text() | ||||
|     if (!svg.includes('passed')) throw new Error('last gitlab pipeline failed') | ||||
|   } catch ({ message }) { | ||||
|     throw new Error(message) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| const f = async () => { | ||||
|   let isMirror = false | ||||
| 
 | ||||
|  | @ -27,6 +38,7 @@ const f = async () => { | |||
|       gotStream(artifactsUrl), | ||||
|       createWriteStream(zipPath) | ||||
|     ) | ||||
|     await pipelineStatus(pipelineUrl) | ||||
|   } catch ({ message }) { | ||||
|     console.error(JSON.stringify({ | ||||
|       error: message, | ||||
|  |  | |||
|  | @ -1,9 +1,10 @@ | |||
| #!/bin/sh | ||||
| 
 | ||||
| CURL_STATUS=$(curl -sSIL "https://gitlab.com/curben/phishing-filter/-/jobs/artifacts/main/download?job=pages" | grep -F "HTTP/2 200") | ||||
| ARTIFACT_STATUS=$(curl -sSIL "https://gitlab.com/curben/phishing-filter/-/jobs/artifacts/main/download?job=pages" | grep -F "HTTP/2 200") | ||||
| PIPELINE_STATUS=$(curl -sSL "https://gitlab.com/curben/phishing-filter/badges/main/pipeline.svg" | grep -F "failed") | ||||
| GITLAB_STATUS="up" | ||||
| 
 | ||||
| if [ -z "$CURL_STATUS" ]; then | ||||
| if [ -z "$ARTIFACT_STATUS" ] || [ -n "$PIPELINE_STATUS" ]; then | ||||
|   GITLAB_STATUS="down" | ||||
| fi | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue