Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ jobs:

- name: Lint Frontend
run: npx biome check

- name: Lint TS errors
run: |
php artisan wayfinder:generate
npx vue-tsc --noEmit --checkJs --project tsconfig.json
49 changes: 29 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,47 @@ on:
jobs:
ci:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: secret
POSTGRES_DB: test_db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.4
tools: composer:v2
coverage: xdebug

- name: Setup Node
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install Node Dependencies
run: npm ci

- name: Install Dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Copy Environment File
run: cp .env.example .env

- name: Generate Application Key
run: php artisan key:generate

- name: Build Assets
run: npm run build
- run: npm ci
- run: composer install --no-interaction --prefer-dist --optimize-autoloader
- run: cp .env.example .env
- run: php artisan key:generate
- run: npm run build

- name: Tests
env:
DB_CONNECTION: pgsql
DB_HOST: 127.0.0.1
DB_PORT: 5432
DB_DATABASE: test_db
DB_USERNAME: test
DB_PASSWORD: secret
run: ./vendor/bin/pest
88 changes: 84 additions & 4 deletions app/Console/Commands/LoadProLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ private function saveProLang(array $item) {
'name' => $yearGroup['name'],
),
array(
'apiId' => $yearGroup['id'],
'position' => $yearGroup['position'],
'name' => $yearGroup['name'],
'apiId' => $yearGroup['id'] ?? null,
'position' => $yearGroup['position'] ?? null,
'name' => $yearGroup['name'] ?? null,
));

$updatedLang = ProLang::updateOrCreate(
Expand Down Expand Up @@ -118,12 +118,92 @@ private function getLanguages(int $page) {
}

/**
* Execute the console command.
* Add some languages like Phel missing in prolang api
*/
private function addProLanguage() {
$langToAdd = array(
// Data : https://phel-lang.org/ and preums itselft
array(
'authors' => array(),
'company' => null,
'id' => uniqid().'_Phel',
'link' => '',
'name' => 'Phel',
'predecessors' => array(),
'yearGroup' => array(
'name' => '2020s',
),
'years' => array(2020),
),
// Data : https://janet-lang.org/ and preums itselft
array(
'authors' => array(),
'company' => null,
'id' => uniqid().'_Janet',
'link' => '',
'name' => 'Janet',
'predecessors' => array(),
'yearGroup' => array(
'name' => '2010s',
),
'years' => array(2017),
),
);

foreach ($langToAdd as $item) {
$this->saveProLang($item);
Log::info('action=add_missing_lang, status=succes, lang='.$item['name']);
}
}

/**
* Add links between languages
* - Some data are missing from prolang api
* - Ex : Php is Hack's predecessors
*/
private function updateLangFamily() {
$langFamilies = array(
// Data: https://github.com/janet-lang/janet
'Janet' => array('C'),
// Data : https://phel-lang.org/
'Phel' => array('PHP', 'Clojure', 'Janet', 'Lisp'),
// https://en.wikipedia.org/wiki/PHP
'PHP' => array('C', 'C++', 'Perl'),
// Data : https://en.wikipedia.org/wiki/Hack_(programming_language)
'Hack' => array('PHP', 'OCaml', 'Java', 'Scala', 'Haskell', 'C#'),
// Data : https://crystal-lang.org/ and https://en.wikipedia.org/wiki/Crystal_(programming_language)
'Crystal' => array('Ruby', 'Go'),
// Data : https://en.wikipedia.org/wiki/Ruby_(programming_language)
'Ruby' => array('Ada', 'Eiffel', 'Lua', 'Dylan'),
// Data : https://en.wikipedia.org/wiki/Dylan_(programming_language)
'Dylan' => array('ALGOL 60', 'EuLisp'),
// Data : https://en.wikipedia.org/wiki/Lasso_(programming_language)
'Lasso' => array('Dylan', 'Scala'),
);

foreach ($langFamilies as $name => $value) {
$lang = ProLang::where('name', $name)->first();
if ($lang) {
$parents = ProLang::whereIn(
'name', $value
)->pluck('id');

$lang->parents()->sync($parents);
$lang->save();

Log::info("action=save_lang, status=success, lang=$name");
} else {
Log::info("action=save_lang, status=failed, reason=lang $name not found");
}
}
}

public function handle() {
Log::info('action=load_prolang_command, status=started');

$this->getLanguages(1);
$this->addProLanguage();
$this->updateLangFamily();

Log::info('action=load_prolang_command, status=finished');
}
Expand Down
11 changes: 9 additions & 2 deletions app/Console/Commands/ProLangAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,12 @@ function member
),
'Common Lisp' => array(),
'Windows PowerShell' => array(),
'Phel' => array(
'mainRepository' => 'https://github.com/phel-lang/phel-lang',
),
'Janet' => array(
'mainRepository' => 'https://github.com/janet-lang/janet',
),
);

DB::transaction(function () use ($langsData) {
Expand All @@ -1141,9 +1147,10 @@ function member
*/
public function handle() {
Log::info('action=prolang_assets_command, status=started');
$this->updateAssets();
Log::info('action=prolang_assets_command, status=finished');

$this->updateAssets();
$this->updateLinks();

Log::info('action=prolang_assets_command, status=finished');
}
}
37 changes: 37 additions & 0 deletions app/Models/ProLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\DB;

/**
* @property int $id
Expand All @@ -21,6 +22,8 @@
class ProLang extends Model {
protected $guarded = array('id');

protected $appends = array('paths');

protected $casts = array(
'years' => 'array',
);
Expand Down Expand Up @@ -52,4 +55,38 @@ public function authors(): BelongsToMany {
public function authorNames(): array {
return $this->authors()->pluck('name')->toArray();
}

// paths

public function getPathsAttribute() {
$targetId = DB::table('pro_langs')->where('id', $this->id)->value('id');

$paths = DB::select("
WITH RECURSIVE paths AS (
SELECT
l.id,
l.name,
l.name::text AS path
FROM pro_langs l
WHERE NOT EXISTS (
SELECT 1 FROM predecessors p WHERE p.child_id = l.id
)

UNION ALL

SELECT
c.id,
c.name,
paths.path || ' -> ' || c.name
FROM paths
JOIN predecessors p ON p.parent_id = paths.id
JOIN pro_langs c ON c.id = p.child_id
)
SELECT path
FROM paths
WHERE id = ?
", array($targetId));

return array_map(fn ($r) => $r->path, $paths);
}
}
Loading