From 261b5c68a70716b6ec64f0770fe4a7114b543825 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 26 Feb 2022 23:43:26 +0100 Subject: [PATCH] CI: Add 'deploy-branch.yml' workflow to update website on branch updates --- .github/actions/install/action.yml | 10 ++- .github/workflows/deploy-branch.yml | 97 +++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy-branch.yml diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 7150c9a..8068e8c 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -2,6 +2,10 @@ name: Install Pico CMS description: Install Pico CMS to the current working directory inputs: + path: + description: Install Pico CMS in directory. + required: false + default: . php-version: description: PHP version to setup. required: true @@ -20,6 +24,7 @@ runs: - name: Read Pico version shell: bash + working-directory: ${{ inputs.path }} run: | PICO_VERSION="$(php -r 'require("./lib/Pico.php"); echo Pico::VERSION;')" echo "PICO_VERSION=$PICO_VERSION" | tee -a "$GITHUB_ENV" @@ -27,6 +32,7 @@ runs: - name: Setup Composer if: ${{ github.ref_type == 'branch' }} shell: bash + working-directory: ${{ inputs.path }} run: | COMPOSER_ROOT_VERSION= @@ -40,8 +46,9 @@ runs: - name: Get Composer cache directory shell: bash + working-directory: ${{ inputs.path }} run: | - COMPOSER_CACHE_DIR="$(composer config cache-dir)" + COMPOSER_CACHE_DIR="$(composer config --global cache-dir)" echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV" - name: Restore Composer cache @@ -54,5 +61,6 @@ runs: - name: Install Composer dependencies shell: bash + working-directory: ${{ inputs.path }} run: | composer install diff --git a/.github/workflows/deploy-branch.yml b/.github/workflows/deploy-branch.yml new file mode 100644 index 0000000..c8fd01b --- /dev/null +++ b/.github/workflows/deploy-branch.yml @@ -0,0 +1,97 @@ +name: Git branch deployment + +on: + push: + branches: + - 'master' + - 'pico-3.0' + +env: + WEBSITE_REPO_SLUG: picocms/picocms.github.io + WEBSITE_REPO_BRANCH: master + CI_TOOLS_SETUP: https://raw.githubusercontent.com/picocms/ci-tools/master/setup.sh + +jobs: + website: + name: Update website for branch updates + + runs-on: ubuntu-latest + permissions: + contents: write + + env: + PHP_VERSION: '7.4' + BUILD_DIR: ./build + WEBSITE_DIR: ./website + + steps: + - name: Setup CI tools + run: | + . <(curl -fsS -L "$CI_TOOLS_SETUP") + echo "CI_TOOLS_PATH=$CI_TOOLS_PATH" | tee -a "$GITHUB_ENV" + + - name: Checkout repository + uses: actions/checkout@v2 + with: + path: ${{ env.BUILD_DIR }} + + - name: Install Pico CMS + uses: ./build/.github/actions/install + with: + path: ${{ env.BUILD_DIR }} + php-version: ${{ env.PHP_VERSION }} + php-tools: phpdoc + + - name: Read Pico milestone + working-directory: ${{ env.BUILD_DIR }} + run: | + PICO_VERSION_MILESTONE="$(php -r 'require("./lib/Pico.php"); preg_match("/^([0-9]+\.[0-9]+)\./", Pico::VERSION, $m); echo $m[1];')" + echo "PICO_VERSION_MILESTONE=$PICO_VERSION_MILESTONE" | tee -a "$GITHUB_ENV" + + - name: Checkout website repository + uses: actions/checkout@v2 + with: + repository: ${{ env.WEBSITE_REPO_SLUG }} + ref: ${{ env.WEBSITE_REPO_BRANCH }} + path: ${{ env.WEBSITE_DIR }} + + # + # Update phpDoc class docs + # + + - name: Update phpDoc class docs + run: | + "$CI_TOOLS_PATH/generate-phpdoc.sh" \ + "$BUILD_DIR/.phpdoc.xml" \ + "$WEBSITE_DIR/phpDoc/$GITHUB_REF_NAME" \ + "$WEBSITE_DIR/phpDoc/$GITHUB_REF_NAME.cache" \ + "Pico $PICO_VERSION_MILESTONE API Documentation ($GITHUB_REF_NAME branch)" + + - name: Check for phpDoc class docs updates + run: | + PHPDOC_UPDATED="$([ -n "$(git -C "$WEBSITE_DIR" status --porcelain "phpDoc/$GITHUB_REF_NAME.cache")" ] && echo "yes" || echo "no")" + echo "PHPDOC_UPDATED=$PHPDOC_UPDATED" | tee -a "$GITHUB_ENV" + + - name: Update phpDoc class docs list + if: ${{ env.PHPDOC_UPDATED == 'yes' }} + run: | + "$CI_TOOLS_PATH/update-phpdoc-list.sh" \ + "$WEBSITE_DIR/_data/phpDoc.yml" \ + "$GITHUB_REF_NAME" "branch" \ + "$GITHUB_REF_NAME branch" "$(date +%s)" + + - name: Commit phpDoc class docs updates + if: ${{ env.PHPDOC_UPDATED == 'yes' }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + repository: ${{ env.WEBSITE_DIR }} + file_pattern: >- + phpDoc/${{ github.ref_name }} + phpDoc/${{ github.ref_name }}.cache + _data/phpDoc.yml + commit_user_name: Pico CMS Bot + commit_user_email: bot@picocms.org + commit_message: >- + Update phpDocumentor class docs + for ${{ github.ref_name }} branch + @ ${{ github.sha }}