Skip to content

Commit

Permalink
Merge branch 'main' of github.com:EpitechPromo2027/B-FUN-500-BAR-5-2-…
Browse files Browse the repository at this point in the history
…glados-oriol.linan into 11-token-to-ast
  • Loading branch information
oriollinan committed Dec 7, 2024
2 parents 4815c62 + c4a1dd3 commit fd56b0d
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 37 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"features": {
"ghcr.io/devcontainers-extra/features/haskell:2": {
"ghcVersion": "9.4.8",
"cabalVersion": "3.10.3.0",
"cabalVersion": "3.12.1.0",
"globalPackages": "hspec-discover hpc-codecov hlint ormolu"
},
"ghcr.io/devcontainers-contrib/features/pipx-package:1": {
"package": "pre-commit"
}
},
"ghcr.io/devcontainers-contrib/features/deno:1": {}
}
}
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Jabolol
lib/Codegen/* @Jabolol
60 changes: 27 additions & 33 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,65 @@
name: Main
name: Coverage Report

on: [push]

jobs:
check_coverage:
permissions:
contents: write
runs-on: ${{ github.repository_owner == 'EpitechPromo2027' && 'self-hosted' || 'ubuntu-latest' }}
if: github.repository_owner != 'EpitechPromo2027'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache GHCup
uses: actions/cache@v4
id: ghcup-cache
with:
path: /home/runner/.ghcup
key: ${{ runner.os }}-ghcup-${{ hashFiles('**/*.cabal') }}
restore-keys: |
${{ runner.os }}-ghcup-
- name: Cache Cabal
uses: actions/cache@v4
id: cabal-cache
with:
path: /home/runner/.cabal
key: ${{ runner.os }}-cabal-${{ hashFiles('**/*.cabal') }}
restore-keys: |
${{ runner.os }}-cabal-
- name: Install required packages
run: sudo apt update && sudo apt install -y build-essential libffi-dev libgmp-dev zlib1g-dev

- name: Setup Haskell
if: ${{ steps.cabal-cache.outputs.cache-hit != 'true' && steps.ghcup-cache.outputs.cache-hit != 'true' }}
uses: ./external/haskell-setup
with:
ghc-version: 9.4.8
cabal-version: 3.10.3.0
cabal-version: 3.12.1.0

- name: Setup Deno
if: github.ref == 'refs/heads/main'
uses: ./external/setup-deno
with:
deno-version: v2.x

- name: Setup Chrome
uses: ./external/setup-chrome
if: github.ref == 'refs/heads/main'
id: setup-chrome
with:
chrome-version: stable
install-dependencies: true

- name: Install dependencies
if: ${{ steps.cabal-cache.outputs.cache-hit != 'true' }}
run: |
cabal update
cabal install hspec-discover hpc-codecov --overwrite-policy=always
- name: Setup environment
if: ${{ steps.cabal-cache.outputs.cache-hit == 'true' && steps.ghcup-cache.outputs.cache-hit == 'true' }}
run: |
echo "/home/runner/.cabal/bin" >> $GITHUB_PATH
echo "/home/runner/.ghcup/bin" >> $GITHUB_PATH
- name: Build project
run: cabal build --jobs=1
run: cabal build

- name: Test project
run: |
cabal configure --enable-coverage --disable-library-coverage
cabal test --jobs=1
cabal configure --enable-coverage
cabal test
- name: Generate coverage report
run: |
hpc-codecov cabal:glados-test --exclude Main,Paths_glados --out codecov.json --format codecov --verbose
- name: Send coverage report
- name: Publish coverage report to Discord
if: github.ref == 'refs/heads/main'
run: |
deno run -A scripts/publish-coverage.ts ${{ secrets.WEBHOOK_URL }} ${{ steps.setup-chrome.outputs.chrome-path }}
- name: Send coverage report to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Release Workflow

on:
workflow_dispatch:

jobs:
build:
strategy:
matrix:
os:
- ubuntu-latest
- macos-14
- macos-13
runs-on: "${{ matrix.os }}"
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install required packages
if: matrix.os == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y build-essential libffi-dev libgmp-dev zlib1g-dev

- name: Install required packages
if: matrix.os == 'macos-14' || matrix.os == 'macos-13'
run: brew install libffi zlib

- name: Setup Haskell
uses: ./external/haskell-setup
with:
ghc-version: 9.4.8
cabal-version: 3.12.1.0

- name: Build project
run: cabal build

- name: Get binary path
run: |
mv "$(cabal list-bin exe:glados)" "$(cabal list-bin exe:glados)_$(uname -s)_$(uname -m)"
echo "GLADOS_BIN=$(cabal list-bin exe:glados)_$(uname -s)_$(uname -m)" >> $GITHUB_ENV
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os }}-artifact"
path: |
${{ env.GLADOS_BIN }}
overwrite: true

release:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true

- name: Determine release body
id: release_body
run: |
if [ -z "$(git tag --list)" ]; then
git log --oneline --no-decorate > release_body.txt
else
latest_tag=$(git describe --tags --abbrev=0)
git log ${latest_tag}..HEAD --oneline --no-decorate > release_body.txt
fi
- name: Create Release
uses: softprops/action-gh-release@master
with:
tag_name: draft
draft: true
files: |
artifacts/*
body_path: release_body.txt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ cabal.project.local~
venv/
*.tix
codecov.json
.vscode/
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
[submodule "external/actions-gh-pages"]
path = external/actions-gh-pages
url = git@github.com:peaceiris/actions-gh-pages.git
[submodule "external/setup-deno"]
path = external/setup-deno
url = git@github.com:denoland/setup-deno.git
[submodule "external/setup-chrome"]
path = external/setup-chrome
url = git@github.com:browser-actions/setup-chrome.git
branch = latest
1 change: 1 addition & 0 deletions external/setup-chrome
Submodule setup-chrome added at facf10
1 change: 1 addition & 0 deletions external/setup-deno
Submodule setup-deno added at 56da42
1 change: 0 additions & 1 deletion glados.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ source-repository head
common warnings
ghc-options:
-Wall
-fhpc

library
import: warnings
Expand Down
100 changes: 100 additions & 0 deletions scripts/publish-coverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/// <reference lib="dom" />

import { $ } from "npm:zx";
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";

const WEBHOOK_URL = Deno.args[0];
const CHROME_PATH = Deno.args[1];

if (!WEBHOOK_URL) {
throw new Error("WEBHOOK_URL is not set");
}

if (!CHROME_PATH) {
throw new Error("CHROME_PATH is not set");
}

const hpcRootPath =
await $`find dist-newstyle -name hpc_index.html | head -n 1`;

const browser = await puppeteer.launch({
args: [
"--no-sandbox",
"--disable-dev-shm-usage",
],
executablePath: CHROME_PATH,
});

const page = await browser.newPage();

await page.goto(`file://${Deno.cwd()}/${hpcRootPath.stdout.trim()}`);

const { width, height } = await page.evaluate(() => {
const body = document.body;
const html = document.documentElement;

const contentWidth = Math.max(
body.scrollWidth,
body.offsetWidth,
html.clientWidth,
html.scrollWidth,
html.offsetWidth,
);
const contentHeight = Math.max(
body.scrollHeight,
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight,
);

return { width: contentWidth, height: contentHeight };
});

await page.setViewport({ width, height });

await page.screenshot({ path: "coverage.png", type: "png" });

await browser.close();

const form = new FormData();

const gitCommitHash = (await $`git rev-parse HEAD`).stdout.trim();

form.append(
"payload_json",
JSON.stringify({
embeds: [
{
title: "HPC Test Report",
description: `\`\`\`md\n# ${gitCommitHash}\n\`\`\``,
image: {
url: "attachment://coverage.png",
},
color: 0x36393f,
},
],
}),
);

form.append(
"file2",
new Blob([await Deno.readFile(`./coverage.png`)], { type: "image/png" }),
"coverage.png",
);

const req = await fetch(WEBHOOK_URL, {
body: form,
method: "POST",
});

if (!req.ok) {
await fetch(WEBHOOK_URL, {
method: "POST",
body: JSON.stringify(
`\`\`\`json\n${JSON.stringify(await req.json(), null, 2)}\n\`\`\``,
),
});
}

await $`rm coverage.png`;

0 comments on commit fd56b0d

Please # to comment.