From 753477caaf900d22523355aad6a758d100897e8f Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sun, 22 Nov 2020 12:01:43 +0100 Subject: [PATCH] Split up GitHub Actions workflows --- .github/workflows/build.yml | 60 +++++++++++ .github/workflows/ci.yml | 153 ---------------------------- .github/workflows/documentation.yml | 57 +++++++++++ .github/workflows/publish.yml | 99 ++++++++++++++++++ package.json | 2 +- 5 files changed, 217 insertions(+), 154 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/documentation.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..8585944c6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,60 @@ +# Copyright (c) 2016-2020 Martin Donath + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +name: build +on: + - push + - pull_request + +env: + NODE_VERSION: 12.x + +jobs: + build: + name: Build project + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Node.js runtime + uses: actions/setup-node@v1 + with: + python-version: ${{ env.NODE_VERSION }} + + - name: Setup Node.js dependency cache + uses: actions/cache@v2 + id: cache + with: + path: node_modules + key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} + + - name: Setup Node.js dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: npm install + + - name: Check project + run: npm run lint + + - name: Build project + run: | + npm run build + git diff --name-only diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index a984354e1..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,153 +0,0 @@ -# Copyright (c) 2016-2020 Martin Donath - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. - -name: ci -on: - - push - - pull_request - -# Environment -env: - CI: true - NODE_VERSION: 10.x - PYTHON_VERSION: 3.x - -# Jobs to run -jobs: - - # Build theme - build: - runs-on: ubuntu-latest - steps: - - # Checkout source form GitHub - - uses: actions/checkout@v2 - - # Install Node runtime and dependencies - - uses: actions/setup-node@v1 - with: - node-version: ${{ env.NODE_VERSION }} - - - uses: actions/cache@v1 - id: cache-node - with: - path: node_modules - key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} - - - if: steps.cache-node.outputs.cache-hit != 'true' - run: npm install - - # Run linter - - run: npm run lint - - # Build distribution files - - run: npm run build - - # Check diff after build - - run: git diff --name-only - - # Build and deploy documentation site - deploy: - if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' - runs-on: ubuntu-latest - steps: - - # Checkout source form GitHub - - uses: actions/checkout@v2 - - # Install Python runtime and dependencies - - uses: actions/setup-python@v1 - with: - python-version: ${{ env.PYTHON_VERSION }} - - # Install theme and dependencies - - run: | - pip install -r requirements.txt - pip install . - pip install \ - mkdocs-minify-plugin>=0.3 \ - mkdocs-redirects>=1.0 - - # Build documentation - - env: - GOOGLE_ANALYTICS_KEY: ${{ secrets.GOOGLE_ANALYTICS_KEY }} - run: | - mkdocs gh-deploy --force - mkdocs --version - - # Publish Python package and Docker image - publish: - if: | - github.repository == 'squidfunk/mkdocs-material' && - startsWith(github.ref, 'refs/tags') - needs: build - runs-on: ubuntu-latest - steps: - - # Checkout source form GitHub - - uses: actions/checkout@v2 - - # Install Node runtime and dependencies - - uses: actions/setup-node@v1 - with: - node-version: ${{ env.NODE_VERSION }} - - - uses: actions/cache@v1 - id: cache-node - with: - path: node_modules - key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} - - - if: steps.cache-node.outputs.cache-hit != 'true' - run: npm install - - # Build distribution files - - run: npm run build - - # Install Python runtime and dependencies - - uses: actions/setup-python@v1 - with: - python-version: ${{ env.PYTHON_VERSION }} - - - run: pip install --upgrade setuptools wheel twine - - # Build and test Docker image - - run: | - docker build -t ${GITHUB_REPOSITORY} . - docker run --rm -i -v $(pwd):/docs ${GITHUB_REPOSITORY} build - - # Build Python package - - run: python setup.py build sdist bdist_wheel --universal - - # Push package to PyPI - - env: - PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: twine upload -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} dist/* - - # Push image to Docker Hub - - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: | - docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD} - docker tag ${GITHUB_REPOSITORY} ${GITHUB_REPOSITORY}:${GITHUB_REF##*/} - docker tag ${GITHUB_REPOSITORY} ${GITHUB_REPOSITORY}:latest - docker push ${GITHUB_REPOSITORY} diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 000000000..ba362bb99 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,57 @@ +# Copyright (c) 2016-2020 Martin Donath + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +name: documentation +on: + push: + branches: + - master + +env: + PYTHON_VERSION: 3.x + +jobs: + documentation: + name: Build documentation + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Python runtime + uses: actions/setup-python@v1 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install Python dependencies + run: | + pip install -r requirements.txt + pip install . + pip install \ + mkdocs-minify-plugin>=0.3 \ + mkdocs-redirects>=1.0 + + - name: Deploy documentation + env: + GOOGLE_ANALYTICS_KEY: ${{ secrets.GOOGLE_ANALYTICS_KEY }} + run: | + mkdocs gh-deploy --force + mkdocs --version diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..c97ff7f91 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,99 @@ +# Copyright (c) 2016-2020 Martin Donath + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +name: publish +on: + release: + types: + - published + +env: + PYTHON_VERSION: 3.x + +jobs: + publish_pypi: + name: Build and push Python package + if: github.event.pull_request.head.repo.fork == false + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Python runtime + uses: actions/setup-python@v1 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Setup Python dependencies + run: pip install --upgrade setuptools wheel twine + + - name: Build Python package + run: python setup.py build sdist bdist_wheel --universal + + - name: Publish Python package + env: + PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: twine upload -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} dist/* + + publish_docker: + name: Build and push Docker image + if: github.event.pull_request.head.repo.fork == false + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Build Docker image + uses: docker/build-push-action@v2 + with: + context: . + tags: | + ${GITHUB_REPOSITORY}:latest + ${GITHUB_REPOSITORY}:${{ github.event.release.tag_name }} + ghcr.io/${GITHUB_REPOSITORY}:latest + ghcr.io/${GITHUB_REPOSITORY}:${{ github.event.release.tag_name }} + + - name: Check Docker image + run: + docker run --rm -i -v ${PWD}:/docs ${GITHUB_REPOSITORY} build + + - name: Publish Docker image + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + docker push --quiet ${GITHUB_REPOSITORY} + docker push --quiet ghcr.io/${GITHUB_REPOSITORY} diff --git a/package.json b/package.json index 4b204ea8c..2d3bcf237 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,6 @@ "webpack-cli": "^4.2.0" }, "engines": { - "node": ">= 10" + "node": ">= 12" } }