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

added icon generation script & auto update action #1

Merged
merged 6 commits into from
Jul 21, 2021
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
111
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REPOSITORY=file-icons/icons
BRANCH=master
81 changes: 81 additions & 0 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Auto Update Icons

on:
schedule:
- cron: '0 0 * * *'

jobs:
generate:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [8.0]
laravel: [^8.0]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Read DotEnv File
uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: .env

- name: Checkout dependent repo
uses: actions/checkout@v2
with:
repository: ${{ env.REPOSITORY }}
ref: ${{ env.BRANCH }}
path: ./dist

- id: latest-commit
name: Get the latest commit
run: |
echo 'LATEST_COMMIT<<EOF' >> $GITHUB_ENV
cd ./dist && git log --format="%H" -n 1 >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV

- id: current-commit
name: Get current commot
uses: juliangruber/read-file-action@v1
with:
path: ./.commit

- name: Add versions to environment
run: |
echo "CURRENT_COMMIT=${{ steps.current-commit.outputs.content }}" >> $GITHUB_ENV

- name: Output versions
run: |
echo "Current commit: ${{ env.CURRENT_COMMIT }}"
echo "Latest commit: ${{ env.LATEST_COMMIT }}"

- name: Install dependencies
run: composer update --no-interaction --no-progress --dev

- name: Compile icons to resources directory
if: env.CURRENT_COMMIT != env.LATEST_COMMIT
run: ./vendor/bin/blade-icons-generate

- name: Update commit hash in ".commit"
if: env.CURRENT_COMMIT != env.LATEST_COMMIT
run: echo ${{ env.LATEST_COMMIT }}>./.commit

- name: Create PR for latest version
if: env.CURRENT_COMMIT != env.LATEST_COMMIT
uses: peter-evans/create-pull-request@v3
with:
commit-message: "auto-update: update icons with the latest commit ${{ env.LATEST_COMMIT }}"
committer: GitHub Action <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: "chore: update icons with the latest commit v${{ env.LATEST_COMMIT }}"
body: |
This updates from [${{ env.CURRENT_COMMIT }}](https://github.com/${{ env.REPOSITORY }}/commit/${{ env.CURRENT_COMMIT }}) to [${{ env.LATEST_COMMIT }}](https://github.com/${{ env.REPOSITORY }}/commit/${{ env.LATEST_COMMIT }}).
Check out the differences: [`${{ env.CURRENT_COMMIT }}` ... `${{ env.LATEST_COMMIT }}`](https://github.com/${{ env.REPOSITORY }}/compare/${{ env.CURRENT_COMMIT }}...${{ env.LATEST_COMMIT }})
branch: feature/update-${{ env.LATEST_COMMIT }}
39 changes: 39 additions & 0 deletions .github/workflows/psp-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Check & fix styling

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [8.0]
laravel: [^8.0]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
coverage: none

- name: Install dependencies
run: composer update --prefer-dist --no-interaction --no-progress

- name: Run PHP CS Fixer
run: vendor/bin/php-cs-fixer fix

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
phpunit.xml
vendor
.phpunit.result.cache
.php_cs.cache
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"illuminate/support": "^8.0"
},
"require-dev": {
"codeat3/blade-icon-generation-helpers": "dev-poc",
"codeat3/phpcs-styles": "dev-main",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.0"
Expand Down
51 changes: 51 additions & 0 deletions config/generation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Codeat3\BladeIconGeneration\Exceptions\InvalidFileExtensionException;
use Codeat3\BladeIconGeneration\IconProcessor;

$svgNormalization = static function (string $tempFilepath, array $iconSet) {

// perform generic optimizations
$iconProcessor = new IconProcessor($tempFilepath, $iconSet);
$iconProcessor
->optimize(pre: function (&$svgEL) {
$width = $svgEL->getAttribute('width');
$height = $svgEL->getAttribute('height');

$viewBox = '0 0 '.str_replace('px', '', $width).' '.str_replace('px', '', $height);
$svgEL->setAttribute('viewBox', $viewBox);
})
->postOptimizationAsString(function ($svgLine){
// remove style and all the class attributes
$replacePatterns = [
'/\s(class=\"[a-z0-9A-Z]+\")/' => '',
'/\<style.*\>.*\<\/style\>/' => '',
];

$svgLine = preg_replace(array_keys($replacePatterns), array_values($replacePatterns), $svgLine);

return $svgLine;
})
->save();

};

return [
[
// Define a source directory for the sets like a node_modules/ or vendor/ directory...
'source' => __DIR__.'/../dist/svg/',

// Define a destination directory for your icons. The below is a good default...
'destination' => __DIR__.'/../resources/svg',

// Enable "safe" mode which will prevent deletion of old icons...
'safe' => true,

// Call an optional callback to manipulate the icon
// with the pathname of the icon and the settings from above...
'after' => $svgNormalization,

'is-solid' => true,

],
];
2 changes: 1 addition & 1 deletion resources/svg/1c-alt.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/svg/1c.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/svg/3d-model.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/svg/3ds-max.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.