Skip to content

Commit

Permalink
refactor: github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed May 11, 2024
1 parent 7117486 commit a108476
Show file tree
Hide file tree
Showing 11 changed files with 5,134 additions and 85 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ end_of_line = crlf

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

# These are supported funding model platforms

patreon: roxblnfk
127 changes: 127 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---

on: # yamllint disable-line rule:truthy
push:
tags:
- '*.*.*'

name: 📦 Build PHAR release

jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 4
strategy:
matrix:
php-version:
- '8.2'
dependencies:
- locked
env:
TRAP_PHAR: ".build/phar/trap.phar"
TRAP_PHAR_SIGNATURE: ".build/phar/trap.phar.asc"
GPG_KEYS: ".build/phar/keys.asc"
GPG_KEYS_ENCRYPTED: "phar/keys.asc.gpg"
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🛠️ Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets
ini-values: error_reporting=E_ALL
coverage: none
tools: phive

- name: 🛠️ Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: 🔍 Get composer cache directory
uses: wayofdev/gh-actions/actions/composer/[email protected]

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/[email protected]
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
uses: wayofdev/gh-actions/actions/composer/[email protected]
with:
dependencies: ${{ matrix.dependencies }}

- name: 📥 Install dependencies with phive
uses: wayofdev/gh-actions/actions/phive/[email protected]
with:
phive-home: '.phive'
trust-gpg-keys: '0xC00543248C87FB13,0x033E5F8D801A2F8D,0x2DF45277AEF09A2F'

- name: 🔍 Validate configuration for box-project/box
run: .phive/box validate box.json.dist --ansi

- name: 🤖 Compile trap.phar with box-project/box
run: .phive/box compile --ansi

- name: 💥 Show info about trap.phar with box-project/box
run: .phive/box info ${{ env.TRAP_PHAR }} --ansi

- name: 🤔 Run trap.phar help command
run: ${{ env.TRAP_PHAR }} --help

- name: 🔍 Show gpg version
run: gpg --version

- name: 🔑 Decrypt keys.asc.gpg with gpg
run: gpg --batch --output ${{ env.GPG_KEYS }} --passphrase \"${{ secrets.GPG_DECRYPT_PASSPHRASE }}\" --yes --decrypt ${{ env.GPG_KEYS_ENCRYPTED }}

- name: 📥 Import keys from keys.asc with gpg
run: gpg --batch --import ${{ env.GPG_KEYS }}

- name: 🔐 Sign trap.phar with gpg
run: gpg --armor --local-user \"${{ secrets.GPG_LOCAL_USER }}\" --output ${{ env.TRAP_PHAR_SIGNATURE }} --passphrase \"${{ secrets.GPG_KEY_PASSPHRASE }}\" --pinentry-mode loopback --yes --detach-sig ${{ env.TRAP_PHAR }}

- name: ❎ Remove decrypted keys.asc
run: rm ${{ env.GPG_KEYS }}

- name: 🏷️ Determine tag
run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"

- name: 📤 Upload release assets
uses: actions/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const fs = require("fs");
const files = [
{
name: "trap.phar",
path: process.env.TRAP_PHAR,
},
{
name: "trap.phar.asc",
path: process.env.TRAP_PHAR_SIGNATURE,
},
];
for (const file of files) {
try {
await github.rest.repos.uploadReleaseAsset({
data: fs.readFileSync(file.path),
name: file.name,
origin: process.env.RELEASE_UPLOAD_URL,
owner: context.repo.owner,
release_id: process.env.RELEASE_ID,
repo: context.repo.repo,
});
} catch (error) {
core.setFailed(error.message);
}
}
81 changes: 0 additions & 81 deletions .github/workflows/cs-fixser.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/lint-php-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---

on: # yamllint disable-line rule:truthy
pull_request:
paths:
- 'src/**'
- 'tests/**'
- 'bin/trap'
- '.php-cs-fixer.php.dist'
push:
paths:
- 'src/**'
- 'tests/**'
- 'bin/trap'
- '.php-cs-fixer.php.dist'

name: 🧹 Fix PHP coding standards

jobs:
coding-standards:
runs-on: ubuntu-latest
timeout-minutes: 4
strategy:
matrix:
php-version:
- '8.2'
dependencies:
- locked
permissions:
contents: write
steps:
- name: ⚙️ Set git to use LF line endings
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: 🛠️ Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets
ini-values: error_reporting=E_ALL
coverage: none

- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🛠️ Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: 🔍 Get composer cache directory
uses: wayofdev/gh-actions/actions/composer/[email protected]

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/[email protected]
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
uses: wayofdev/gh-actions/actions/composer/[email protected]
with:
dependencies: ${{ matrix.dependencies }}

- name: 🛠️ Prepare environment
run: make prepare

- name: 🚨 Run coding standards task
run: composer cs:diff
env:
PHP_CS_FIXER_IGNORE_ENV: true

- name: 📤 Commit and push changed files back to GitHub
uses: stefanzweifel/[email protected]
with:
commit_message: 'style(php-cs-fixer): lint php files and fix coding standards'
branch: ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---

name: Testing

on: [push, pull_request]
on: # yamllint disable-line rule:truthy
- push
- pull_request

jobs:
unit:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
!/.github/
/runtime/
/vendor/
/composer.lock
/.env
*.log
File renamed without changes.
56 changes: 56 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---

extends: default

ignore: |
.build/
vendor/
bin/
rules:
braces:
# Defaults
# min-spaces-inside: 0
# max-spaces-inside: 0

# Keep 0 min-spaces to not error on empty {} collection definitions
min-spaces-inside: 0

# Allow one space inside braces to improve code readability
max-spaces-inside: 1

brackets:
# Defaults
# min-spaces-inside: 0
# max-spaces-inside: 0

# Keep 0 min-spaces to not error on empty [] collection definitions
min-spaces-inside: 0

# Allow one space inside braces to improve code readability
max-spaces-inside: 1

colons:
# Defaults
# min-spaces-before: 0
# max-spaces-after: 1

# Allow multiple spaces after a colon to allow indentation of YAML
# dictionary values
max-spaces-after: -1

commas:
# Defaults
# max-spaces-after: 1

# Allow multiple spaces after a comma to allow indentation of YAML
# dictionary values
max-spaces-after: -1

comments:
require-starting-space: true
min-spaces-from-content: 1

line-length: disable

...
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"sort-packages": true
},
"scripts": {
"cs-check": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run",
"cs-fix": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -vvv --using-cache=no"
"cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
"cs:fix": "php vendor/bin/php-cs-fixer fix -v"
}
}
Loading

0 comments on commit a108476

Please sign in to comment.