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

Prepare workflow and raport-regression script for Github Page #147

Merged
merged 9 commits into from
May 23, 2023
79 changes: 79 additions & 0 deletions .github/actions/push-raport-to-gh-pages/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "Push raport to gh-pages"
description: "Used to push a raport file to the gh-pages branch for the webiste to be updated"
inputs:
artifact-name:
description: "Name of the artifact that has been uploaded"
required: true
file-to-pick:
description: "Name of the file that has been uploaded and should be picked for the raport"
required: true
build-title:
description: "Title of the post file that will be created"
required: true
token:
description: "Token for pushing"
required: true

runs:
using: "composite"
steps:
- name: Git Checkout
uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact-name }}
path: ~/

- name: Add front matter to the file
shell: bash
run: ./scripts/insert_post_front_matter.sh ~/${{ inputs.file-to-pick }} ${{ inputs.build-title }}

- name: Git Checkout
uses: actions/checkout@v3
with:
ref: gh-pages
token: ${{ inputs.token }}

- name: Exit if artifact file is empty
shell: bash
run: |
if [ ! -s ~/${{ inputs.file-to-pick }} ]; then
echo "::warning title=GH page upload failure::The input file ${{ inputs.file-to-pick }} is empty"
exit 0
fi
- name: Add the raport to _post dir and push
shell: bash
run: |
# Get filename in lowercase kebab-case
normalized_build_title="$(echo '${{ inputs.build-title }}' | tr '[:upper:]' '[:lower:]' | tr ' ' '-')"
filename="$(date -u '+%Y-%m-%d')-$normalized_build_title.md"

# create _posts dir if not exists
mkdir -p "./_posts"

# Find raport from same compiler version
same_ver_pattern=".*-$normalized_build_title\.md"

# Find first match
file_path=$(find "./_posts" -type f -regex "$same_ver_pattern" -print -quit)

# Check if a file was found and replace it
if [[ -n "$file_path" ]]; then
cat ~/${{ inputs.file-to-pick }} > $file_path
if [[ $file_path != ./_posts/"$filename" ]]; then
mv $file_path ./_posts/"$filename"
fi
else
cat ~/${{ inputs.file-to-pick }} > ./_posts/"$filename"
fi

git config --global user.name "GitHub Actions"
git config --global user.email "scala3-community-build@virtuslab.com"

git add ./_posts/"$filename"
git commit -m "Upload build raport: ${{ inputs.build-title }}"
git push origin gh-pages

- name: Git Checkout
uses: actions/checkout@v3
25 changes: 22 additions & 3 deletions .github/workflows/buildExecuteCustom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ on:
type: string
description: "List of scalacOptions which should be filtered out when building projects."
default: ""
push-to-gh-pages:
type: boolean
description: "Should the workflow push the generated raport to gh-pages branch"
default: false
jobs:
# Name of this job need to match inputs of build-project/job-info
execute-build-plan:
Expand Down Expand Up @@ -60,12 +64,27 @@ jobs:
lastRC="$(./scripts/lastVersionRC.sc)"
lastStable=$(./scripts/lastVersionStable.sc)

./scripts/raport-regressions.scala $scalaVersion > raport-full.md
./scripts/raport-regressions.scala $scalaVersion --compareWith=$lastRC > raport-compare-$lastRC.md
./scripts/raport-regressions.scala $scalaVersion --compareWith=$lastStable > raport-compare-$lastStable.md
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion > raport-full.md
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion --compareWith=$lastRC > raport-compare-$lastRC.md
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion --compareWith=$lastStable > raport-compare-$lastStable.md

- name: Upload raports
uses: actions/upload-artifact@v3
with:
name: build-raports
path: ${{ github.workspace }}/raport-*.md

- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: 303718
private_key: ${{ secrets.OPENCB_CONFIG_UPDATE_TOKEN }}

- name: Push raport
if: ${{ inputs.push-to-gh-pages == 'true' }}
uses: ./.github/actions/push-raport-to-gh-pages
with:
artifact-name: build-raports
file-to-pick: raport-full.md
build-title: ${{ needs.execute-build-plan.outputs.used-scala-version }}
token: ${{ steps.generate-token.outputs.token }}
22 changes: 18 additions & 4 deletions .github/workflows/buildExecuteScheduledWeekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,31 @@ jobs:
lastRC="$(./scripts/lastVersionRC.sc)"
lastStable=$(./scripts/lastVersionStable.sc)

./scripts/raport-regressions.scala $scalaVersion > raport-full.md
./scripts/raport-regressions.scala $scalaVersion --compareWith=$lastRC > raport-compare-$lastRC.md
./scripts/raport-regressions.scala $scalaVersion --compareWith=$lastStable > raport-compare-$lastStable.md
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion > raport-full.md
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion --compareWith=$lastRC > raport-compare-$lastRC.md
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion --compareWith=$lastStable > raport-compare-$lastStable.md

lastWeeklyVersionFile=./last-successfull-weekly-version
lastWeeklyVersion=$(cat $lastWeeklyVersionFile) && \
./scripts/raport-regressions.scala $scalaVersion --compareWith=$lastWeeklyVersion > raport-compare-$lastWeeklyVersion.md || true
scala-cli scripts/raport-regressions.scala scripts/md_printer.scala -- $scalaVersion --compareWith=$lastWeeklyVersion > raport-compare-$lastWeeklyVersion.md || true
echo "$scalaVersion" > $lastWeeklyVersionFile

- name: Upload raports
uses: actions/upload-artifact@v3
with:
name: build-raports
path: ${{ github.workspace }}/raport-*.md

- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: 303718
private_key: ${{ secrets.OPENCB_CONFIG_UPDATE_TOKEN }}

- name: Push raport
uses: ./.github/actions/push-raport-to-gh-pages
with:
artifact-name: build-raports
file-to-pick: raport-full.md
build-title: ${{ needs.execute-build-plan.outputs.used-scala-version }}
token: ${{ steps.generate-token.outputs.token }}
11 changes: 5 additions & 6 deletions .github/workflows/compare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ jobs:
env:
ES_USER: ${{ secrets.OPENCB_ELASTIC_USER }}
ES_PASSWORD: ${{ secrets.OPENCB_ELASTIC_PSWD }}
run: |
./scripts/raport-regressions.scala \
${{ inputs.scala-version }} \
--compareWith=${{ inputs.compare-with-scala-version }} \
--buildId=${{ inputs.build-id }} \
--compareWithBuildId=${{ inputs.compare-with-build-id }}
run: scala-cli scripts/raport-regressions.scala scripts/console_printer.scala -- \
${{ inputs.scala-version }} \
--compareWith=${{ inputs.compare-with-scala-version }} \
--buildId=${{ inputs.build-id }} \
--compareWithBuildId=${{ inputs.compare-with-build-id }}
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ node_modules
/tmp

# scala-cli
**/.scala-build
**/.scala-build

# jekyll
_site
.sass-cache
.jekyll-cache
.jekyll-metadata
vendor
18 changes: 18 additions & 0 deletions scripts/console_printer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
object Printer {
import scala.Console
val RED = Console.RED
val YELLOW = Console.YELLOW
val MAGENTA = Console.MAGENTA
val RESET = Console.RESET
val BOLD = Console.BOLD
val LINE_BREAK = ""

def println(text: String): Unit = Predef.println(text)
def log(text: String) = Predef.println(text)
def printLine() = println("-" * 20)
def projectUrlString(projectName: String, version: String, buildUrl: String): String = {
val projectVerString = if version.isEmpty then projectName else s"$projectName @ $version"

if buildUrl.isEmpty then projectVerString else s"$projectVerString - $buildUrl"
}
}
26 changes: 26 additions & 0 deletions scripts/insert_post_front_matter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

filename="$1"
title="$2"

if [ -z "$filename" ]; then
echo "Provide a filename as an argument."
exit 1
fi

if [ -z "$title" ]; then
echo "Provide a title as an argument."
exit 1
fi

date=$(date -u "+%Y-%m-%d %H:%M:%S")

echo "---" > "$filename.tmp"
echo "layout: post" >> "$filename.tmp"
echo "title: \"$title\"" >> "$filename.tmp"
echo "date: $date" >> "$filename.tmp"
echo "---" >> "$filename.tmp"
echo "" >> "$filename.tmp"

cat "$filename" >> "$filename.tmp"
mv "$filename.tmp" "$filename"
19 changes: 19 additions & 0 deletions scripts/md_printer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
object Printer {
val RED = """<span style="color:red">"""
val YELLOW = """<span style="color:yellow">"""
val MAGENTA = """<span style="color:magenta">"""
val RESET = """</span>"""
val BOLD = """<span style="font-weight:bold">"""
val LINE_BREAK = "<br>"

def println(text: String): Unit = Predef.println(s"$text")
def log(text: String) = ()
def printLine() = println("<hr>")

/** make project name be a clickable link to the build */
def projectUrlString(projectName: String, version: String, buildUrl: String): String = {
val projectVerString = if version.isEmpty then projectName else s"$projectName @ $version"

if buildUrl.isEmpty then projectVerString else s"[$projectVerString]($buildUrl)"
}
}
Loading