diff --git a/.github/workflows/pr_info.yml b/.github/workflows/pr_info.yml new file mode 100644 index 0000000..66ee441 --- /dev/null +++ b/.github/workflows/pr_info.yml @@ -0,0 +1,69 @@ +name: PR Info + +# This workflow builds the whole project once and: +# - comments build deprecations/warnings (highlighting new ones since last tested PR) + +on: + pull_request: + branches: + - master + - stable + +jobs: + pr_info: + name: PR Info + runs-on: ubuntu-20.04 + steps: + - name: 'Prepare sticky comment' + # commit of v2.5.0 + # same one used again at the bottom of the file to update the comment. + uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd + with: + message: | + Thanks for your Pull Request and making D better! + + This comment will automatically be updated to summarize some statistics in a few minutes. + only_create: true + + - name: '[Linux] Install dependencies' + if: runner.os == 'Linux' + run: | + sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev netcat + + # Compiler to test with + - name: Prepare compiler + uses: dlang-community/setup-dlang@v1 + with: + compiler: ldc-latest + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Checkout old stuff, with new comment script + run: | + git checkout ${{ github.base_ref }} + git checkout ${{ github.sha }} -- ./scripts/ci/summary_comment.sh ./scripts/ci/summary_comment_diff.sh + + # first dump old info + + - name: Check pre-PR status + run: ./scripts/ci/summary_comment.sh | tee ../OLD_OUTPUT.txt + + - name: Checkout PR target + run: | + git checkout ${{ github.sha }} + git clean -fd + git reset --hard + + - name: Evaluate PR + run: ./scripts/ci/summary_comment.sh | tee ../NEW_OUTPUT.txt + + - name: Generate comment + run: ./scripts/ci/summary_comment_diff.sh ../OLD_OUTPUT.txt ../NEW_OUTPUT.txt | tee comment.txt + + - name: Update GitHub comment + uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd + with: + path: comment.txt diff --git a/scripts/ci/summary_comment.sh b/scripts/ci/summary_comment.sh new file mode 100755 index 0000000..fb1f2bf --- /dev/null +++ b/scripts/ci/summary_comment.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -u + +# Output from this script is piped to a file by CI, being run from before a +# change has been made and after a change has been made. Then both outputs are +# compared using summary_comment_diff.sh + +# cd to git folder, just in case this is manually run: +ROOT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")/../../" && pwd )" +cd ${ROOT_DIR} + +dub --version +ldc2 --version + +# fetch missing packages before timing +dub upgrade --missing-only + +start=`date +%s` +dub build --build=release --force 2>&1 || echo "BUILD FAILED" +end=`date +%s` +build_time=$( echo "$end - $start" | bc -l ) + +strip bin/dub + +echo "STAT:statistics (-before, +after)" +echo "STAT:executable size=$(wc -c bin/dub)" +echo "STAT:rough build time=${build_time}s" diff --git a/scripts/ci/summary_comment_diff.sh b/scripts/ci/summary_comment_diff.sh new file mode 100755 index 0000000..4831abe --- /dev/null +++ b/scripts/ci/summary_comment_diff.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash + +set -u + +EMPTY=1 + +ADDED=$(diff --new-line-format='%L' --old-line-format='' --unchanged-line-format='' "$1" "$2") +REMOVED=$(diff --new-line-format='' --old-line-format='%L' --unchanged-line-format='' "$1" "$2") +TOTAL=$(cat "$2") + +STATS_OLD=$(grep -E '^STAT:' "$1" | sed -E 's/^STAT://') +STATS_NEW=$(grep -E '^STAT:' "$2" | sed -E 's/^STAT://') + +STATS_DIFFED=$(diff --new-line-format='+%L' --old-line-format='-%L' --unchanged-line-format=' %L' <(echo "$STATS_OLD") <(echo "$STATS_NEW")) + +ADDED_DEPRECATIONS=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$ADDED") +REMOVED_DEPRECATIONS=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$REMOVED") +ADDED_WARNINGS=$(grep -Pi '\b(warn|warning)\b' <<< "$ADDED") +REMOVED_WARNINGS=$(grep -Pi '\b(warn|warning)\b' <<< "$REMOVED") + +DEPRECATION_COUNT=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$TOTAL" | wc -l) +WARNING_COUNT=$(grep -Pi '\b(warn|warning)\b' <<< "$TOTAL" | wc -l) + +if [ -z "$ADDED_DEPRECATIONS" ]; then + # no new deprecations + true +else + echo "⚠️ This PR introduces new deprecations:" + echo + echo '```' + echo "$ADDED_DEPRECATIONS" + echo '```' + echo + EMPTY=0 +fi + +if [ -z "$ADDED_WARNINGS" ]; then + # no new deprecations + true +else + echo "⚠️ This PR introduces new warnings:" + echo + echo '```' + echo "$ADDED_WARNINGS" + echo '```' + echo + EMPTY=0 +fi + +if grep "BUILD FAILED" <<< "$TOTAL"; then + echo '❌ Basic `dub build` failed! Please check your changes again.' + echo +else + if [ -z "$REMOVED_DEPRECATIONS" ]; then + # no removed deprecations + true + else + echo "✅ This PR fixes following deprecations:" + echo + echo '```' + echo "$REMOVED_DEPRECATIONS" + echo '```' + echo + EMPTY=0 + fi + + if [ -z "$REMOVED_WARNINGS" ]; then + # no removed warnings + true + else + echo "✅ This PR fixes following warnings:" + echo + echo '```' + echo "$REMOVED_WARNINGS" + echo '```' + echo + EMPTY=0 + fi + + if [ $EMPTY == 1 ]; then + echo "✅ PR OK, no changes in deprecations or warnings" + echo + fi + + echo "Total deprecations: $DEPRECATION_COUNT" + echo + echo "Total warnings: $WARNING_COUNT" + echo +fi + +if [ -z "$STATS_DIFFED" ]; then + # no statistics? + true +else + echo "Build statistics:" + echo + echo '```diff' + echo "$STATS_DIFFED" + echo '```' + echo +fi + +echo '
' +echo +echo 'Full build output' +echo +echo '```' +echo "$TOTAL" +echo '```' +echo +echo '
'