Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundlewatch check on PR comment #37

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9e24f8c
test: add bundlewatch check on PR comment Refs #2262124
Jun 19, 2024
b5065bb
test: remove link from status message Refs #2262124
Jun 19, 2024
9bf84a7
test: remove link from status message Refs #2262124
Jun 19, 2024
38bbaea
test: test fail message
Jun 19, 2024
b1d4892
test: check failure
Jun 19, 2024
ecc57d6
Fix format of changelog in extration
Jun 19, 2024
31d6b24
Fix format of changelog in extration
Jun 19, 2024
08391d1
Fix format of changelog in extration
Jun 19, 2024
fba488a
fix on failure
valentinab25 Jun 25, 2024
c218528
test: fix error message
valentinab25 Jun 25, 2024
6d103d8
test: add try/catch in case of error
valentinab25 Jun 25, 2024
e7383f4
test: fix Jenkinsfile
valentinab25 Jun 25, 2024
74b64e6
test: debug
valentinab25 Jun 25, 2024
785900d
test: debug
valentinab25 Jun 25, 2024
cd237a5
test: debug
valentinab25 Jun 25, 2024
a747f58
test: remove publish check
valentinab25 Jun 25, 2024
0b7238c
test: add error log
valentinab25 Jun 25, 2024
840516b
test: debug
valentinab25 Jun 26, 2024
efe8f6b
test: remove unused code
valentinab25 Jun 26, 2024
58bd341
test: debug succes
valentinab25 Jun 27, 2024
7f9073c
test: Jenkinsfile fix
valentinab25 Jun 27, 2024
6cf69f7
test: debug
valentinab25 Jun 27, 2024
59a75f2
test: try master branch
Jul 3, 2024
3989778
test: try master branch
Jul 3, 2024
539c509
test: try master branch
Jul 3, 2024
d525d58
test: try master branch
Jul 3, 2024
be75f13
test: try master branch
Jul 3, 2024
b2d660c
test: debug
Jul 3, 2024
987b71a
test: debug
valentinab25 Jul 4, 2024
5109544
test: debug
valentinab25 Jul 4, 2024
0d78c64
test: try demo
Jul 22, 2024
250b3ca
test: fix
valentinab25 Jul 23, 2024
960987a
test: if diff size 0, put full log in status
valentinab25 Jul 23, 2024
aa4558a
test: test size difference
valentinab25 Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/bundlewatch-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Auto Comment
on: [pull_request]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: wow-actions/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: |
👋 @{{ author }}

To check bundle size on a frontend, write comment with:
> @eea-jenkins check bundle on FRONTEND-NAME

Example:
> @eea-jenkins check bundle on eea-website-frontend
87 changes: 85 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ pipeline {
tools {
jdk 'Java17'
}

triggers {
issueCommentTrigger('[^>]*@eea-jenkins.*check bundle on.*')
}

environment {
GIT_NAME = "volto-anchors"
NAMESPACE = "@eeacms"
Expand All @@ -18,6 +23,82 @@ pipeline {
}

stages {


stage('Pull Request COMMENT') {
when {
not { environment name: 'CHANGE_ID', value: '' }
not { environment name: 'GITHUB_COMMENT', value: '' }
}
agent {
node { label 'docker-big-jobs' }
}
steps {
script {
env.NODEJS_HOME = "${tool 'NodeJS'}"
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
env.CI=false
env.FRONTEND_NAME = (env.GITHUB_COMMENT =~ /@eea-jenkins check bundle on (\S+).*$/)[ 0 ][ 1 ]
sh '''rm -rf ${FRONTEND_NAME}'''
sh '''git clone -b develop https://github.com/eea/${FRONTEND_NAME}.git'''
dir(env.FRONTEND_NAME) {
sh """cat mrs.developer.json | jq '.[].branch="master"' | jq 'if ( has("'$GIT_NAME'") ) then .["'$GIT_NAME'"].branch = "'$CHANGE_BRANCH'" else . end' > temp"""
sh """mv temp mrs.developer.json"""
sh """cat mrs.developer.json | jq '.["'$GIT_NAME'"]' """
sh '''if [ $(grep "eea/"${GIT_NAME}".git" mrs.developer.json | wc -l) -eq 0 ]; then exit 1; fi'''
sh """yarn"""
sh """make develop"""
sh """make install"""
sh """make build"""
try {
sh """set -o pipefail; yarn bundlewatch --config .bundlewatch.config.json 2>&1 | tee checkresult.txt"""
}
finally {
sh '''du build/public/static/js/ | awk '{print $1}' > new_size '''
sh """cat mrs.developer.json | jq '.[].branch="develop"' > temp"""
sh """mv temp mrs.developer.json"""
sh """make develop"""
sh """make install"""
sh """make build"""
sh '''du build/public/static/js/ | awk '{print $1}' > old_size '''
sh """yarn bundlewatch --config .bundlewatch.config.json 2>&1 | tee checkresult2.txt"""
sh """grep -v 'https://service.bundlewatch.io/results' checkresult.txt > result.txt"""
sh """grep -v 'https://service.bundlewatch.io/results' checkresult2.txt > result2.txt"""
sh """diff result.txt result2.txt | grep static > diffresult.txt"""
}
env.difference = readFile(file: 'new_size').toInteger() - readFile(file: 'old_size').toInteger()
if ( env.difference == 0 ) {
sh """cp result.txt diffresult.txt"""
}
publishChecks name: "Bundlewatch on ${env.FRONTEND_NAME}", title: "Bundle size check on ${env.FRONTEND_NAME}", summary: "Result of bundlewatch run on ${env.FRONTEND_NAME}",
text: readFile(file: 'diffresult.txt'), conclusion: "${currentBuild.currentResult}",
detailsURL: "${env.BUILD_URL}display/redirect"
pullRequest.comment("### :heavy_check_mark: Bundlewatch check passed on ${FRONTEND_NAME}:\nTotal size difference $difference\n${BUILD_URL}${GIT_NAME}/\n\n:rocket: @${GITHUB_COMMENT_AUTHOR}")
}

}
}
post {
failure {
script {
try {
sh """cat $FRONTEND_NAME/diffresult.txt"""

pullRequest.comment("### :x: Bundlewatch check failed on ${FRONTEND_NAME}:\nTotal size difference $difference\n${BUILD_URL}${GIT_NAME}/\n\n:rocket: @${GITHUB_COMMENT_AUTHOR}")

publishChecks name: "Bundlewatch on ${env.FRONTEND_NAME}", title: "Bundle size check on ${env.FRONTEND_NAME}", summary: "Result of bundlewatch run on ${env.FRONTEND_NAME}",
text: readFile(file: "diffresult.txt"), conclusion: "${currentBuild.currentResult}",
detailsURL: "${env.BUILD_URL}display/redirect"

}
catch (Exception e) {
pullRequest.comment("### :x: Bundlewatch check job on ${FRONTEND_NAME} could not run\n\nCheck if frontend name ${FRONTEND_NAME} is written correctly, then check if $GIT_NAME is present in mrs.developer.json and try again\n\n${BUILD_URL} for details\n\n:fire: @${GITHUB_COMMENT_AUTHOR}")
}
}
}
}
}

stage('Release') {
when {
allOf {
Expand Down Expand Up @@ -61,7 +142,9 @@ pipeline {
anyOf {
allOf {
not { environment name: 'CHANGE_ID', value: '' }
environment name: 'GITHUB_COMMENT', value: ''
environment name: 'CHANGE_TARGET', value: 'develop'
environment name: 'GITHUB_COMMENT', value: ''
}
allOf {
environment name: 'CHANGE_ID', value: ''
Expand Down Expand Up @@ -347,6 +430,7 @@ pipeline {
anyOf {
allOf {
not { environment name: 'CHANGE_ID', value: '' }
environment name: 'GITHUB_COMMENT', value: ''
environment name: 'CHANGE_TARGET', value: 'develop'
environment name: 'SKIP_TESTS', value: ''
}
Expand Down Expand Up @@ -377,6 +461,7 @@ pipeline {
not {
environment name: 'CHANGE_ID', value: ''
}
environment name: 'GITHUB_COMMENT', value: ''
environment name: 'CHANGE_TARGET', value: 'master'
}
steps {
Expand All @@ -395,8 +480,6 @@ pipeline {
post {
always {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
changed {
script {
def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.currentResult}</h1>
<p>Check console output at <a href="${env.BUILD_URL}/display/redirect">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p>
Expand Down
Loading