Skip to content

Commit b3a4ae7

Browse files
committed
(PA-3883) Add GitHub Actions workflow that shows component diff
1 parent 24d5b7a commit b3a4ae7

File tree

5 files changed

+419
-0
lines changed

5 files changed

+419
-0
lines changed

Diff for: .github/workflows/comment_on_pr.yaml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
name: Comment output on PR
3+
4+
on:
5+
workflow_run:
6+
workflows: ["Vanagon Component Diff"]
7+
types:
8+
- completed
9+
10+
jobs:
11+
upload:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: 'Download artifacts'
16+
uses: actions/[email protected]
17+
with:
18+
script: |
19+
var artifacts = await github.actions.listWorkflowRunArtifacts({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
run_id: ${{github.event.workflow_run.id }},
23+
});
24+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
25+
return artifact.name == "artifacts"
26+
})[0];
27+
var download = await github.actions.downloadArtifact({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
artifact_id: matchArtifact.id,
31+
archive_format: 'zip',
32+
});
33+
var fs = require('fs');
34+
fs.writeFileSync('${{github.workspace}}/artifacts.zip', Buffer.from(download.data));
35+
fs.writeFileSync('./artifactid', matchArtifact.id)
36+
37+
- name: 'Unzip artifacts'
38+
run: unzip artifacts.zip
39+
40+
- name: 'Check comment limits'
41+
run: |
42+
chars=$(cat ./text | wc -m)
43+
if ((chars > 65300)); then
44+
# Trim output to 65300 characters
45+
truncate -s 65300 ./text
46+
47+
# Close all code blocks
48+
nr_code_keyword=$(cat ./text | grep '\`\`\`' | wc -l)
49+
if [ $((nr_code_keyword%2)) -ne 0 ];then
50+
echo >> ./text
51+
echo "\`\`\`" >> ./text
52+
fi
53+
54+
# Close all collapsible blocks
55+
nr_open_details=$(cat ./text | grep '<details>' | wc -l)
56+
nr_closed_details=$(cat ./text | grep '</details>' | wc -l)
57+
for i in `seq $(($nr_open_details-$nr_closed_details))`; do echo >> ./text; echo "</details>" >> ./text;done
58+
59+
# Output artifact info
60+
echo >> ./text
61+
echo "# ..." >> ./text
62+
echo >> ./text
63+
printf "Comment size limit reached. " >> ./text
64+
echo "Please download full artifacts from [here](https://github.com/${{ github.repository }}/suites/${{github.event.workflow_run.check_suite_id }}/artifacts/$(cat ./artifactid))." >> ./text
65+
fi
66+
67+
- name: 'Add comment'
68+
uses: actions/github-script@v3
69+
with:
70+
script: |
71+
var fs = require('fs');
72+
var issue_number = Number(fs.readFileSync('./nr'));
73+
var issue_text = String(fs.readFileSync('./text'));
74+
await github.issues.createComment({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
issue_number: issue_number,
78+
body: issue_text
79+
});

Diff for: .github/workflows/component_diff_check.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Vanagon Component Diff
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- master
8+
9+
jobs:
10+
vanagon_component_diff_check:
11+
runs-on: ubuntu-latest
12+
name: Check
13+
steps:
14+
- name: Checkout current PR
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install ruby version ${{ matrix.cfg.ruby }}
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: 2.7
23+
24+
- name: Bundle project
25+
run: |
26+
gem install bundler
27+
bundle config set without packaging documentation
28+
bundle install --jobs 3 --retry 3 --with development
29+
30+
- name: Save artifacts data
31+
run: |
32+
mkdir -p ./output
33+
echo '${{ github.event.number }}' > ./output/nr
34+
bundle exec rake vanagon:component_diff -- '-mpall' > ./output/text
35+
cat ./output/text
36+
37+
- name: Upload artifacts
38+
uses: actions/upload-artifact@v2
39+
with:
40+
name: artifacts
41+
path: output/

Diff for: Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ gem 'vanagon', *location_for(ENV['VANAGON_LOCATION'] || '~> 0.21')
1515
gem 'packaging', *location_for(ENV['PACKAGING_LOCATION'] || '~> 0.99.8')
1616
gem 'rake', '~> 12.0'
1717

18+
group(:development, optional: true) do
19+
gem 'highline', require: false
20+
gem 'parallel', require: false
21+
gem 'colorize', require: false
22+
gem 'hashdiff', require: false
23+
end
24+
1825
#gem 'rubocop', "~> 0.34.2"
1926

2027
eval_gemfile("#{__FILE__}.local") if File.exist?("#{__FILE__}.local")

Diff for: Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ rescue LoadError => e
77
puts "Error loading packaging rake tasks: #{e}"
88
end
99

10+
Dir.glob(File.join('tasks/**/*.rake')).each { |file| load file }
11+
1012
namespace :package do
1113
task :bootstrap do
1214
puts 'Bootstrap is no longer needed, using packaging-as-a-gem'

0 commit comments

Comments
 (0)