Skip to content

Commit

Permalink
ci: Add github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Dec 18, 2023
1 parent 5a736e7 commit 6a42773
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/llvm-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
schedule:
- cron: "0 */1 * * *"

workflow_dispatch:

jobs:
build:
concurrency:
group: single
cancel-in-progress: false

runs-on: self-hosted

permissions:
issues: write

steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Set up Git
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Update LLVM
run: ${{ github.workspace }}/scripts/update_llvm.sh

- name: Update optimized IR
id: update
run: ${{ github.workspace }}/scripts/update_optimized.sh

- name: Report
uses: JasonEtco/create-an-issue@v2
if: steps.update.outputs.SHOULD_OPEN_ISSUE == '1'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: scripts/issue.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bench_build
llvm-build
CHANGELOGS
28 changes: 28 additions & 0 deletions scripts/gen_issue_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python3
import sys
import html

commit_hash = sys.argv[1]
report_file = "scripts/issue.md"

def dump_pretty_change_logs(report, change_logs_path):
report.write('## Change Logs\n')

with open(change_logs_path, "r") as change_logs:
for line in change_logs.readlines():
if len(line) > 40 and line[:40].isalnum() and not line.startswith('from'):
commit_id = line[:40]
remain = line[40:]
report.write(
"[{0}](https://github.com/llvm/llvm-project/commit/{0}){1}\n".format(commit_id, html.escape(remain.removesuffix('\n'))))
else:
report.write(line)

with open(report_file, 'w') as issue_report:
issue_report.write('---\n')
issue_report.write(
"title: Update diff {{ date | date('MMMM Do YYYY, h:mm:ss a') }}\n")
issue_report.write('---\n')
issue_report.write('commit: {}\n'.format(commit_hash))
issue_report.write('\n')
dump_pretty_change_logs(issue_report, 'CHANGELOGS')
3 changes: 3 additions & 0 deletions scripts/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Internal CI Error
---
10 changes: 10 additions & 0 deletions scripts/update_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -euo pipefail
shopt -s inherit_errexit

last_commit=$(git -C llvm/llvm-project rev-parse HEAD)
git submodule update --remote --merge llvm/llvm-project
current_commit=$(git -C llvm/llvm-project rev-parse HEAD)
echo -e "from $last_commit to $current_commit\n" > CHANGELOGS
git log $last_commit..HEAD --pretty=oneline >> CHANGELOGS
cat CHANGELOGS
28 changes: 28 additions & 0 deletions scripts/update_optimized.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

mkdir -p llvm/llvm-build
cd llvm/llvm-build
cmake ../llvm-project/llvm -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -G Ninja \
-DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_ENABLE_WARNINGS=OFF -DLLVM_APPEND_VC_REV=OFF -DLLVM_TARGETS_TO_BUILD="X86;" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build . -j -t opt
cd ../..

scripts/gen_optimized.py bench $LLVM_OPT_BENCHMARK_WORKSPACE/llvm-build/bin/opt
llvm_commit=$(git -C llvm/llvm-project rev-parse HEAD)
git commit -a -m "llvm: Update baseline to $llvm_commit"
if [ $? -eq 0 ]
then
git push -u origin
git show --name-only | grep bench
if [ $? -eq 0 ]
then
scripts/gen_issue_report.py $(git rev-parse HEAD)
echo "SHOULD_OPEN_ISSUE=1" >> $GITHUB_OUTPUT
else
echo "SHOULD_OPEN_ISSUE=0" >> $GITHUB_OUTPUT
fi
else
echo "SHOULD_OPEN_ISSUE=0" >> $GITHUB_OUTPUT
fi

0 comments on commit 6a42773

Please sign in to comment.