From d2e446fbd0029b1830e165c4fd3d9209f83a4ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 6 Jul 2021 18:55:44 +0200 Subject: [PATCH 1/6] Add website build instructions --- README.md | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7170d9a0..5adc051d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ -Website -======= +# Website Source code of reactphp.org. -Setup ------ +## Setup 1. Copy `.env.dist` to `.env` and add a [personal access token](https://github.com/settings/tokens) to the @@ -17,8 +15,36 @@ Setup 2. Install dependencies with `$ composer install`. -Auto-Deployment with Travis CI ------------------------------- +## Build + +Once set up, you can build the website by executing this: + +```bash +$ bin/build +``` + +This script will fetch all project repositories and then rebuild the entire website. +The resulting static website will be built into the `tmp/build` directory. + +If you're working on the website source code, you may want to skip fetching all +components on every build like this: + +```bash +$ bin/build --no-component-update +``` + +If you're working on the website CSS or Javascript code, you will have to +rebuild the static assets like this: + +```bash +$ npm run-script build +``` + +> Note that compiled assets are expected to change much less frequently and are + under version control. Run `npm install` to install and later commit any changes + in `static-files/assets/`. + +## Auto-Deployment with Travis CI The website can be automatically deployed via the Travis CI [GitHub Pages Deployment](https://docs.travis-ci.com/user/deployment/pages/) @@ -29,8 +55,7 @@ on Travis CI: `GITHUB_TOKEN` ([a personal access token](https://docs.travis-ci.com/user/deployment/pages/#Setting-the-GitHub-token)), `DEPLOY_REPO`, `DEPLOY_TARGET_BRANCH` and `DEPLOY_FQDN`. -License -------- +## License Released under the [MIT](LICENSE) license. From ac7f7bb1261f22f8293458863061bae3d08004fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 7 Jul 2021 09:21:10 +0200 Subject: [PATCH 2/6] Update website build to generate same HTML locally (like Travis used to) --- .env.dist | 2 +- composer.json | 5 ++ composer.lock | 132 ++++++++++++++++++++++++++++++++++------ config/berti.config.php | 3 + static-files/CNAME | 1 + 5 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 static-files/CNAME diff --git a/.env.dist b/.env.dist index e5b8bfc0..39e0a359 100644 --- a/.env.dist +++ b/.env.dist @@ -1,4 +1,4 @@ GITHUB_TOKEN="" DEPLOY_REPO="reactphp/reactphp.github.io" DEPLOY_TARGET_BRANCH="master" -DEPLOY_URL="" +DEPLOY_URL="https://reactphp.org" diff --git a/composer.json b/composer.json index 493423ad..04df8b65 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,10 @@ "elvanto/litemoji": "^1.0", "zendframework/zend-feed": "^2.10", "igorw/retry": "^1.0@dev" + }, + "config": { + "platform": { + "php": "7.1.99" + } } } diff --git a/composer.lock b/composer.lock index b8cb9da3..eaa80a25 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "578a0c25d65181f20e9ef4e82912d6ca", + "content-hash": "b87b15b654be84b55654ad4fd82da4b1", "packages": [], "packages-dev": [ { @@ -2136,6 +2136,85 @@ ], "time": "2018-04-26T10:06:28+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.4.0", @@ -2246,31 +2325,31 @@ }, { "name": "twig/twig", - "version": "v2.4.3", + "version": "v2.13.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "eab7c3288ae6603d7d6f92b531626af2b162d1f2" + "reference": "57e96259776ddcacf1814885fc3950460c8e18ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/eab7c3288ae6603d7d6f92b531626af2b162d1f2", - "reference": "eab7c3288ae6603d7d6f92b531626af2b162d1f2", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/57e96259776ddcacf1814885fc3950460c8e18ef", + "reference": "57e96259776ddcacf1814885fc3950460c8e18ef", "shasum": "" }, "require": { - "php": "^7.0", - "symfony/polyfill-mbstring": "~1.0" + "php": ">=7.1.3", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" }, "require-dev": { "psr/container": "^1.0", - "symfony/debug": "~2.7", - "symfony/phpunit-bridge": "~3.3@dev" + "symfony/phpunit-bridge": "^4.4.9|^5.0.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.13-dev" } }, "autoload": { @@ -2292,23 +2371,36 @@ "homepage": "http://fabien.potencier.org", "role": "Lead Developer" }, + { + "name": "Twig Team", + "role": "Contributors" + }, { "name": "Armin Ronacher", "email": "armin.ronacher@active-4.com", "role": "Project Founder" - }, - { - "name": "Twig Team", - "homepage": "http://twig.sensiolabs.org/contributors", - "role": "Contributors" } ], "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "http://twig.sensiolabs.org", + "homepage": "https://twig.symfony.com", "keywords": [ "templating" ], - "time": "2017-06-07T18:47:58+00:00" + "support": { + "issues": "https://github.com/twigphp/Twig/issues", + "source": "https://github.com/twigphp/Twig/tree/v2.13.1" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2020-08-05T15:09:04+00:00" }, { "name": "vlucas/phpdotenv", @@ -2521,5 +2613,9 @@ "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "platform-overrides": { + "php": "7.1.99" + }, + "plugin-api-version": "2.0.0" } diff --git a/config/berti.config.php b/config/berti.config.php index f56677bd..451d36cb 100644 --- a/config/berti.config.php +++ b/config/berti.config.php @@ -6,6 +6,9 @@ // Ignore missing .env } +// use UTC timezone for all dates on website (release dates in changelogs) +date_default_timezone_set('UTC'); + return function (Pimple\Container $container) { $container['markdown.cache'] = function () { return new Symfony\Component\Cache\Adapter\FilesystemAdapter( diff --git a/static-files/CNAME b/static-files/CNAME new file mode 100644 index 00000000..77687c8d --- /dev/null +++ b/static-files/CNAME @@ -0,0 +1 @@ +reactphp.org From 4e5d155bf58637a00a747bc77f7020bd537b9f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 7 Jul 2021 09:37:04 +0200 Subject: [PATCH 3/6] Add deployment instructions --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 5adc051d..f316c2a6 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,25 @@ $ npm run-script build under version control. Run `npm install` to install and later commit any changes in `static-files/assets/`. +## Deploy + +Once built (see previous chapter), deployment is as simple as hosting the static +website contents of the `tmp/build` directory behind a webserver of your choice. + +We use GitHub Pages to deploy this to the live site. This is done by pushing the +contents of the `tmp/build` directory to the repository hosted in +[reactphp/reactphp.github.io](https://github.com/reactphp/reactphp.github.io). + +This deployment can be started by executing this: + +```bash +$ bin/build --deploy +``` + +Note that this will publish any changes you've made to your local repository, +including any uncommitted ones. There should usually be no need to do this +manually, see next chapter for auto-deployment. + ## Auto-Deployment with Travis CI The website can be automatically deployed via the Travis CI From 0baac1dd5d966c482328b24da8bf50fdfe69ff38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 6 Jul 2021 13:50:24 +0200 Subject: [PATCH 4/6] Use GitHub actions for continuous integration (CI) Bye bye Travis CI, you've served us well. --- .github/workflows/ci.yml | 19 +++++++++++++++++++ .travis.yml | 34 ---------------------------------- README.md | 21 +++++++++++++-------- bin/build | 1 - 4 files changed, 32 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a9b95ec1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: Deploy + +on: + push: + workflow_dispatch: + +jobs: + Deploy: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.1 + - run: composer install + - run: mkdir ~/.ssh && echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_rsa && chmod 400 ~/.ssh/id_rsa + - run: echo 'GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"' > .env && cat .env.dist >> .env + - run: git config --global user.name "GitHub Actions" && git config --global user.email "actions@github.com" + - run: bin/build --deploy diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 10f9ad53..00000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: php - -sudo: false - -php: - - 7.1 - -branches: - only: - - master - -cache: - directories: - - $HOME/.composer/cache/files - - tmp/cache - - tmp/components - -before_script: - - composer install - -script: - - ./bin/build - -deploy: - provider: pages - skip_cleanup: true - local_dir: ./tmp/build - project_name: "ReactPHP Website" - fqdn: $DEPLOY_FQDN - repo: $DEPLOY_REPO - target_branch: $DEPLOY_TARGET_BRANCH - github_token: $GITHUB_TOKEN - on: - branch: master diff --git a/README.md b/README.md index f316c2a6..7158ce7e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Website +[![CI status](https://github.com/reactphp/website/workflows/CI/badge.svg)](https://github.com/reactphp/website/actions) + Source code of reactphp.org. ## Setup @@ -63,16 +65,19 @@ Note that this will publish any changes you've made to your local repository, including any uncommitted ones. There should usually be no need to do this manually, see next chapter for auto-deployment. -## Auto-Deployment with Travis CI +## Auto-Deployment + +The website can be automatically deployed via the GitHub Pages feature. -The website can be automatically deployed via the Travis CI -[GitHub Pages Deployment](https://docs.travis-ci.com/user/deployment/pages/) -feature. +Any time a commit is merged (such as when a PR is merged), GitHub actions will +automatically build and deploy the website. This is done by running the above +deployment script (see previous chapter). -Make sure, the required environment variables are set in the repository settings -on Travis CI: `GITHUB_TOKEN` -([a personal access token](https://docs.travis-ci.com/user/deployment/pages/#Setting-the-GitHub-token)), -`DEPLOY_REPO`, `DEPLOY_TARGET_BRANCH` and `DEPLOY_FQDN`. +> Repository setup: +> We're using a SSH deploy key for pushing to this target repository. +> Make sure the required `DEPLOY_KEY` secret is set in the repository settings on GitHub. +> See [action documentation](https://github.com/JamesIves/github-pages-deploy-action#using-an-ssh-deploy-key-) +> for more details. ## License diff --git a/bin/build b/bin/build index 1d16fba1..635bc73a 100755 --- a/bin/build +++ b/bin/build @@ -16,7 +16,6 @@ call_user_func(include $configFile, $container); function run($command, $cwd = null) { $process = new Symfony\Component\Process\Process($command, $cwd); - $process->setTty(true); $process->mustRun(function ($type, $buffer) { echo $buffer; From 87050849d9e1823ceb9c293c512d0e43247c04a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 7 Jul 2021 20:10:44 +0200 Subject: [PATCH 5/6] Retry rendering markdown when hitting rate limit / abuse limit --- src/data.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/data.php b/src/data.php index 15ceebc4..4f2c29be 100644 --- a/src/data.php +++ b/src/data.php @@ -43,11 +43,21 @@ function components(Client $client, CacheItemPoolInterface $markdownCache): arra if ($cacheItem->isHit()) { $html = $cacheItem->get(); } else { - $html = $client->markdown()->render( - $release['body'], - 'gfm', - $component['repository'] - ); + try{ + $html = $client->markdown()->render( + $release['body'], + 'gfm', + $component['repository'] + ); + } catch (\Exception $e) { + echo 'Temporary error, will retry in 60s: ' . $e->getMessage() . PHP_EOL; + sleep(60); + $html = $client->markdown()->render( + $release['body'], + 'gfm', + $component['repository'] + ); + } $cacheItem->set($html); $markdownCache->save($cacheItem); From a7670843023bed0e6849d262b119bd055f1539e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 7 Jul 2021 21:06:22 +0200 Subject: [PATCH 6/6] Build page on all branches including PRs, deploy only on main branch --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9b95ec1..2b3c351b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,7 @@ name: Deploy on: push: + pull_request: workflow_dispatch: jobs: @@ -16,4 +17,6 @@ jobs: - run: mkdir ~/.ssh && echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_rsa && chmod 400 ~/.ssh/id_rsa - run: echo 'GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"' > .env && cat .env.dist >> .env - run: git config --global user.name "GitHub Actions" && git config --global user.email "actions@github.com" - - run: bin/build --deploy + - run: bin/build + - run: bin/build --deploy --no-component-update + if: ${{ github.ref == 'refs/heads/main' }}