diff options
| -rw-r--r-- | .github/workflows/build.yaml | 65 | ||||
| -rw-r--r-- | .github/workflows/lint.yaml (renamed from .github/workflows/lint-build-deploy.yaml) | 83 | ||||
| -rwxr-xr-x | README.md | 8 | 
3 files changed, 85 insertions, 71 deletions
| diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..f133ba24 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,65 @@ +name: Build + +on: +  workflow_run: +    workflows: ["Lint"] +    branches: +      - master +    types: +      - completed + +jobs: +  build: +    if: github.event.workflow_run.conclusion == 'success' +    name: Build, Push, & Deploy Container +    runs-on: ubuntu-latest + +    steps: +      # Create a commit SHA-based tag for the container repositories +      - name: Create SHA Container Tag +        id: sha_tag +        run: | +          tag=$(cut -c 1-7 <<< $GITHUB_SHA) +          echo "::set-output name=tag::$tag" + +      - name: Checkout code +        uses: actions/checkout@v2 + +      - name: Set up Docker Buildx +        uses: docker/setup-buildx-action@v1 + +      - name: Login to Github Container Registry +        uses: docker/login-action@v1 +        with: +          registry: ghcr.io +          username: ${{ github.repository_owner }} +          password: ${{ secrets.GHCR_TOKEN  }} + +      # Build and push the container to the GitHub Container +      # Repository. The container will be tagged as "latest" +      # and with the short SHA of the commit. +      - name: Build and push +        uses: docker/build-push-action@v2 +        with: +          context: . +          file: ./Dockerfile +          push: true +          cache-from: type=registry,ref=ghcr.io/python-discord/seasonalbot:latest +          cache-to: type=inline +          tags: | +            ghcr.io/python-discord/seasonalbot:latest +            ghcr.io/python-discord/seasonalbot:${{ steps.sha_tag.outputs.tag }} + +      - name: Authenticate with Kubernetes +        uses: azure/k8s-set-context@v1 +        with: +          method: kubeconfig +          kubeconfig: ${{ secrets.KUBECONFIG }} + +      - name: Deploy to Kubernetes +        uses: Azure/k8s-deploy@v1 +        with: +          manifests: | +              deployment.yaml +          images: 'ghcr.io/python-discord/seasonalbot:${{ steps.sha_tag.outputs.tag }}' +          kubectl-version: 'latest' diff --git a/.github/workflows/lint-build-deploy.yaml b/.github/workflows/lint.yaml index c70e49b7..063f406c 100644 --- a/.github/workflows/lint-build-deploy.yaml +++ b/.github/workflows/lint.yaml @@ -1,15 +1,15 @@ -name: Lint, Build & Deploy +name: Lint  on:    push:      branches:        - master -  pull_request_target: +  pull_request:  jobs:    lint: -    name: Lint using pre-commit & flake8 +    name: Run pre-commit & flake8      runs-on: ubuntu-latest      env:        # Configure pip to cache dependencies and do a user install @@ -32,12 +32,8 @@ jobs:        - name: Add custom PYTHONUSERBASE to PATH          run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH -      # We don't want to persist credentials, as our GitHub Action -      # may be run when a PR is made from a fork.        - name: Checkout repository          uses: actions/checkout@v2 -        with: -          persist-credentials: false        - name: Setup python          id: python @@ -84,67 +80,14 @@ jobs:        - name: Run pre-commit hooks          run: export PIP_USER=0; SKIP=flake8 pre-commit run --all-files -      # This step requires `pull_request_target` as we need "write" permissions -      # to add annotations to the Actions results. A normal `pull_request` trigger -      # does not get those permissions for security reasons. +      # Run flake8 and have it format the linting errors in the format of +      # the GitHub Workflow command to register error annotations. This +      # means that our flake8 output is automatically added as an error +      # annotation to both the run result and in the "Files" tab of a +      # pull request. +      # +      # Format used: +      # ::error file={filename},line={line},col={col}::{message}        - name: Run flake8 -        uses: julianwachholz/flake8-action@v1 -        with: -          checkName: lint -        env: -          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -  build-and-deploy: -    name: Build and Deploy to Kubernetes -    needs: lint -    if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/master' -    runs-on: ubuntu-latest - -    steps: -      # Create a commit SHA-based tag for the container repositories -      - name: Create SHA Container Tag -        id: sha_tag -        run: | -          tag=$(cut -c 1-7 <<< $GITHUB_SHA) -          echo "::set-output name=tag::$tag" - -      - name: Checkout code -        uses: actions/checkout@v2 - -      - name: Set up Docker Buildx -        uses: docker/setup-buildx-action@v1 - -      - name: Login to Github Container Registry -        uses: docker/login-action@v1 -        with: -          registry: ghcr.io -          username: ${{ github.repository_owner }} -          password: ${{ secrets.GHCR_TOKEN  }} - -      # Build and push the container to the GitHub Container -      # Repository. The container will be tagged as "latest" -      # and with the short SHA of the commit. -      - name: Build and push -        uses: docker/build-push-action@v2 -        with: -          context: . -          file: ./Dockerfile -          push: true -          cache-from: type=registry,ref=ghcr.io/python-discord/seasonalbot:latest -          tags: | -            ghcr.io/python-discord/seasonalbot:latest -            ghcr.io/python-discord/seasonalbot:${{ steps.sha_tag.outputs.tag }} - -      - name: Authenticate with Kubernetes -        uses: azure/k8s-set-context@v1 -        with: -          method: kubeconfig -          kubeconfig: ${{ secrets.KUBECONFIG }} - -      - name: Deploy to Kubernetes -        uses: Azure/k8s-deploy@v1 -        with: -          manifests: | -              deployment.yaml -          images: 'ghcr.io/python-discord/seasonalbot:${{ steps.sha_tag.outputs.tag }}' -          kubectl-version: 'latest' +        run: "flake8 \ +        --format='::error file=%(path)s,line=%(row)d,col=%(col)d::[flake8] %(code)s: %(text)s'" @@ -1,6 +1,7 @@  # SeasonalBot -[ +[![Lint Badge][1]][2] +[![Build Badge][3]][4]  [](https://discord.gg/2B963hn)  A Discord bot for the Python Discord community which changes with the seasons, and provides useful event features. @@ -17,3 +18,8 @@ This later evolved into a bot that runs all year, providing season-appropriate f  Before you start, please take some time to read through our [contributing guidelines](CONTRIBUTING.md).  See [Seasonalbot's Wiki](https://pythondiscord.com/pages/contributing/seasonalbot/) for in-depth guides on getting started with the project! + +[1]:https://github.com/python-discord/seasonalbot/workflows/Lint/badge.svg?branch=master +[2]:https://github.com/python-discord/seasonalbot/actions?query=workflow%3ALint+branch%3Amaster +[3]:https://github.com/python-discord/seasonalbot/workflows/Build/badge.svg?branch=master +[4]:https://github.com/python-discord/seasonalbot/actions?query=workflow%3ABuild+branch%3Amaster | 
