forked from broadinstitute/warp
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (71 loc) · 2.71 KB
/
validate_changelog.yml
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
name: WARP Validate Changelog
# Controls when the workflow will run
on:
#Changing trigger to all PRs for all branches
pull_request:
#branches: [ "develop" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# inputs:
# image_tag:
# description: 'Docker Image Tag (default: branch_name)'
env:
PROJECT_NAME: WARP
# Github repo name
REPOSITORY_NAME: ${{ github.event.repository.name }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# The job that builds our container
validate-changelog:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# defaults:
# run:
# working-directory: tools
# Map a step output to a job output
# outputs:
# imagePath: ${{ steps.saveImagePath.outputs.url }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Check working directory
run: |
echo "Current directory: "
pwd
ls -lht
- name: Set up Git
run: |
git fetch --all
- name: Validate changelogs
id: validate_script
run: |
set -e
echo "Validating changelog for ${{ github.base_ref }}"
result=$(scripts/validate_release.sh -g origin/${{ github.base_ref }} -i true 2>&1 || echo "validation_failed") # don't exit on script failure
# Escape newlines, carriage returns, and percent signs
escaped_result=$(echo "$result" | sed ':a;N;$!ba;s/\r/\\r/g;s/\n/\\n/g;s/%/%%/g')
echo "result=$escaped_result" >> $GITHUB_OUTPUT
- name: Post validation results as a comment
if: always() # This ensures it runs regardless of previous step success/failure
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const output = "${{ steps.validate_script.outputs.result }}".replace(/\\n/g, '\n').replace(/\\r/g, '\r');
const issue_number = context.payload.pull_request.number;
const message = `### 🔍Changelog Validation Results:\n\`\`\`\n${output}\n\`\`\``;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
} catch (error) {
console.error('Failed to post comment:', error);
}
- name: Fail if validation failed
if: contains(steps.validate_script.outputs.result, 'validation_failed')
run: exit 1