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

Improve setup #107

Merged
merged 42 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
73e47b8
Move all code into code/{packages,types,tests}
fefas Jan 8, 2023
439f91b
Rename stack to docker-compose
fefas Jan 8, 2023
338d74b
Fix code after bad phpstorm refactoring
fefas Jan 8, 2023
683c7de
Install phars via composer
fefas Jan 8, 2023
e77b8cc
Update docker config accordingly
fefas Jan 8, 2023
89fc75a
Fix cache
fefas Jan 8, 2023
152f109
Adjust configs
fefas Jan 8, 2023
045d2ef
Update makefiles
fefas Jan 8, 2023
e7a4741
Update composers
fefas Jan 8, 2023
f02acba
Make mutation test green
fefas Jan 9, 2023
a44f7ba
Update pipeline
fefas Jan 9, 2023
caa1bb4
Update pipeline
fefas Jan 9, 2023
689fcb7
Update pipeline
fefas Jan 9, 2023
6e8e6dc
Fix syntax check
fefas Jan 9, 2023
606fe68
Fix folder creation
fefas Jan 9, 2023
175142b
Push and pull on pipeline
fefas Jan 9, 2023
58a6e26
Login docker in pipeline
fefas Jan 9, 2023
282b23d
fix
fefas Jan 9, 2023
afd2853
fix
fefas Jan 9, 2023
8621296
fix
fefas Jan 10, 2023
0574d8d
Update dependabot
fefas Jan 10, 2023
a5211f5
Publish packages
fefas Jan 10, 2023
c3529f5
PR control
fefas Jan 10, 2023
608cf9c
Do not publish if there was no change
fefas Jan 10, 2023
7dfaa21
Make publish is success even if there was no code change
fefas Jan 10, 2023
cca7141
Remove github action ssh step
fefas Jan 12, 2023
2e4ce85
Test simplifying publish
fefas Jan 12, 2023
2193216
Try to push
fefas Jan 12, 2023
673c8ab
fix author
fefas Jan 12, 2023
cfadab0
Fix author again
fefas Jan 12, 2023
33e4bb2
See output
fefas Jan 12, 2023
083046a
Fix author
fefas Jan 12, 2023
92f2876
Use machine user ssh key
fefas Jan 12, 2023
6defcee
test again
fefas Jan 12, 2023
a5f1fe0
Fix publish
fefas Jan 15, 2023
85d1af2
Print info out
fefas Jan 15, 2023
81608fc
Publish after tests
fefas Jan 15, 2023
42311d6
Test
fefas Jan 15, 2023
9c4225e
Fix mutation tests "properly"
fefas Jan 16, 2023
7497ad7
Move types back together with other packages
fefas Jan 16, 2023
9541518
Fix CS
fefas Jan 16, 2023
66bc8fe
Publish type uri
fefas Jan 16, 2023
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
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

11 changes: 10 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ version: 2

updates:
- package-ecosystem: composer
directory: "/"
directory: "/code"
schedule:
interval: daily
time: '04:00'
timezone: Europe/Berlin
assignees:
- fefas
versioning-strategy: increase
- package-ecosystem: composer
directory: "/phars"
schedule:
interval: daily
time: '04:00'
timezone: Europe/Berlin
assignees:
- fefas
versioning-strategy: increase
46 changes: 21 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
name: CI

on: push
concurrency: action-on-${{ github.ref_name }}

env:
revision: ${{ github.sha }}
concurrency: ci-on-${{ github.ref_name }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: docker login ghcr.io -u ${{ github.actor }} -p ${{ github.token }}
- run: make build php=${{ matrix.php }} revision=${{ env.revision }}
strategy:
matrix:
php: [ 8.2.0 ]
steps:
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
- run: make docker/build docker/push php=${{ matrix.php }}

test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- run: make test php=${{ matrix.php }} revision=${{ env.revision }}
strategy:
matrix:
php: [ 8.2.0 ]
level: [ cs, unit, mutation ]
steps:
- uses: actions/checkout@v3
- run: make docker/pull php=${{ matrix.php }}
- run: make tests/${{ matrix.level }} php=${{ matrix.php }}

publish:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- name: Set up deploy key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.PACKAGE_DEPLOY_KEY }}
- name: Set up git author
run: |
git config --global user.name "${{ github.event.commits[0].author.name }}"
git config --global user.email ${{ github.event.commits[0].author.email }}
- run: make publish package=${{ matrix.package }} branch=${{ github.ref_name }} revision=${{ env.revision }}
strategy:
matrix:
package: [ service-resolver ]
package: [ service-resolver, type-uri ]
steps:
- uses: actions/checkout@v3
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.PACKAGE_PUBLISH_KEY }}
- run: make publish package=${{ matrix.package }}

pr-control:
runs-on: ubuntu-latest
needs: [ build, test, publish ]
steps:
- name: You shall pass!
run: echo You shall pass!
- run: echo You shall pass!
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
bin/*
!bin/phive.xml
packages/reports/
temp/
vendor/
var/*
!var/.gitkeep
51 changes: 32 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,51 @@ ARG PHP

FROM php:${PHP}-cli-alpine3.16

ARG DIR_BIN
ARG DIR_PACKAGES
ARG DIR_COMPOSER_VENDOR
ENV HOME_DIR /usr/local/bauhaus
ENV COMPOSER_CODE_DIR $HOME_DIR/composer/code
ENV COMPOSER_PHARS_DIR $HOME_DIR/composer/phars
ENV CACHE_DIR $HOME_DIR/var/cache
ENV CODE_DIR $HOME_DIR/code
ENV PHARS_DIR $HOME_DIR/phars
ENV REPORTS_DIR $HOME_DIR/var/reports

ENV COMPOSER_VENDOR_DIR $DIR_COMPOSER_VENDOR
ENV PATH $PATH:$DIR_BIN
ENV PATH $PATH:$COMPOSER_PHARS_DIR/bin

RUN apk add --no-cache \
$PHPIZE_DEPS \
gnupg \
graphviz \
make \
terminus-font \
vim && \
curl -sSLf \
-o /usr/local/bin/composer \
https://getcomposer.org/download/2.5.1/composer.phar && \
curl -sSLf \
-o /usr/local/bin/install-php-extensions \
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
curl -sSLf \
-o /usr/local/bin/phive \
https://phar.io/releases/phive.phar && \
chmod +x \
/usr/local/bin/install-php-extensions \
/usr/local/bin/phive && \
/usr/local/bin/composer \
/usr/local/bin/install-php-extensions && \
install-php-extensions \
intl \
pcov

WORKDIR $DIR_PACKAGES

COPY ./bin/ $DIR_BIN
RUN cd $DIR_BIN && yes | phive install

COPY ./packages/ $DIR_PACKAGES
RUN cd $DIR_PACKAGES && composer install
pcov && \
adduser bauhaus sudo -u 1000 -h $HOME_DIR -s /sbin/nologin -D && \
mkdir -p \
$COMPOSER_CODE_DIR \
$COMPOSER_PHARS_DIR \
$CACHE_DIR \
$CODE_DIR \
$PHARS_DIR \
$REPORTS_DIR && \
chown -R bauhaus:bauhaus $HOME_DIR

WORKDIR $CODE_DIR
USER bauhaus

COPY --chown=bauhaus:bauhaus phars/ $PHARS_DIR/
COPY --chown=bauhaus:bauhaus code/ $CODE_DIR/

RUN make composer/install

ENTRYPOINT []
100 changes: 39 additions & 61 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
version ?= local
php ?= 8.2.0
revision = dev-${version}-php${php}
MAKEFLAGS += --silent

include stack.config.env
export
export PHP := ${php}
export REVISION := ${revision}
tests/%:
@make docker/run cmd='make ${@}'

build:
@make -s stack cmd=build

test: level ?= all
test:
@make -s stack-run cmd='composer test:${level}'
composer/%:
@make docker/run cmd='make ${@}'

sh:
@make -s stack-run cmd='sh'

#
# Local
local-setup:
@make -s build
@make -s local-cp-files

local-cp-files: localBin = ./bin
local-cp-files: localVendor = ./vendor
local-cp-files:
@rm -rf ${localBin} ${localVendor}
@make -s stack cmd='up -d'
@make -s cp from=${DIR_BIN} to=${localBin}
@make -s cp from=${DIR_COMPOSER_VENDOR} to=${localVendor}
@make -s stack cmd='down --remove-orphans'

cp:
@make -s stack cmd='cp bauhaus:${from} ${to}'

#
# Docker
stackFiles = stack.yaml $(if ${CI},,stack.local.yaml)

stack-files:
@echo ${stackFiles}

stack-dump:
@make -s stack cmd=config

stack-run: options = $(if ${CI},-T)
stack-run:
@make -s stack cmd='run ${options} bauhaus ${cmd}'

stack: stack = $(addprefix -f,${stackFiles})
stack:
@docker compose ${stack} ${cmd}
@make docker/run cmd=sh

#
# Release
publish: remote = [email protected]:bauhausphp/${package}.git
publish: commit = Ref bauhausphp/bauhaus@${revision}
publish: source = packages/src/${package}
publish: destination = temp/${package}
publish: branch = $(shell git rev-parse --abbrev-ref HEAD)
publish: commit = Ref bauhausphp/bauhaus@${version}
publish: author-name = $(shell git --no-pager show -s --format='%an' HEAD)
publish: author-email = $(shell git --no-pager show -s --format='%ae' HEAD)
publish: workdir = ./var/tmp/${package}
publish:
rm -rf ${destination}
git clone -b ${branch} ${remote} ${destination} || git clone ${remote} ${destination}
rsync --archive --verbose --exclude .git --delete-after ${source}/ ${destination}
git -C ${destination} add .
git -C ${destination} commit --message '${commit}' || echo 'No change'
git -C ${destination} push -u origin HEAD:${branch}
@rm -rf ${workdir}
@git clone -b ${branch} ${remote} ${workdir} || git clone ${remote} ${workdir}
@rsync --quiet --archive --verbose --exclude .git --delete-after ./code/packages/${package}/ ${workdir}
@git -C ${workdir} status --porcelain
@if [ "$$(git -C ${workdir} status --porcelain)" ]; then \
git -C ${workdir} config user.name "${author-name}"; \
git -C ${workdir} config user.email ${author-email}; \
git -C ${workdir} add .; \
git -C ${workdir} commit --message "${commit}"; \
git -C ${workdir} push -u origin HEAD:${branch}; \
fi;

docker: php ?= 8.2.0
docker: version = $(shell git rev-parse --short HEAD)
docker: revision = dev-${version}-php${php}
docker: files = $(addprefix -f,$(shell make -s docker/files))
docker:
@TAG=${revision} PHP=${php} docker compose ${files} ${cmd}

docker/files:
@echo docker-compose.yaml $(if ${CI},,docker-compose.local.yaml)

docker/run: options = --no-deps $(if ${CI},-T)
docker/run:
@make docker cmd='run ${options} bauhaus ${cmd}'

docker/%:
@make docker cmd='${*}'
8 changes: 0 additions & 8 deletions bin/phive.xml

This file was deleted.

31 changes: 31 additions & 0 deletions code/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
MAKEFLAGS += --silent
.PHONY: tests

tests:
@make tests/unit
@make tests/mutation

tests/cs:
@phpcs -ps \
--cache=${CACHE_DIR}/phpcs.cache

tests/unit:
@phpunit \
--cache-result-file ${CACHE_DIR}/phpunit.cache \
--coverage-clover ${REPORTS_DIR}/clover.xml \
--coverage-html ${REPORTS_DIR}/coverage

tests/mutation:
@infection run -s -j4

composer/install: composer/phars/install composer/code/install

composer/phars/%:
@make composer cmd=${*} workDir=${PHARS_DIR} vendorDir=${COMPOSER_PHARS_DIR}

composer/code/%:
@make composer cmd=${*} workDir=${CODE_DIR} vendorDir=${COMPOSER_CODE_DIR}

composer:
@composer -d ${workDir} config vendor-dir ${vendorDir}
@composer -d ${workDir} ${cmd}
3 changes: 3 additions & 0 deletions code/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once "{$_ENV['COMPOSER_CODE_DIR']}/autoload.php";
22 changes: 22 additions & 0 deletions code/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "project",
"license": "MIT",

"autoload": {
"psr-4": { "Bauhaus\\Tests\\": "./tests/"}
},

"require": {
"bauhaus/service-resolver": "dev-main",
"bauhaus/type-uri": "dev-main"
},

"repositories": [
{ "type":"path", "url": "./packages/*/" }
],

"config": {
"sort-packages": false,
"vendor-dir": "/usr/local/bauhaus/composer/phars"
}
}
6 changes: 3 additions & 3 deletions packages/composer.lock → code/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/deptrac.yaml → code/deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ deptrac:

- name: TypeUri
collectors:
- { type: directory, value: ./src/type-uri/public/ }
- { type: directory, value: ./src/type-uri/private/, private: true }
- { type: directory, value: ./src/uri/public/ }
- { type: directory, value: ./src/uri/private/, private: true }

- name: TestServiceResolver
collectors:
Expand Down
Loading