From c80ebe8d0eebc7833d74646e4d013f69543da376 Mon Sep 17 00:00:00 2001 From: Ben Chambers <35960+bjchambers@users.noreply.github.com> Date: Wed, 31 Jan 2024 09:28:50 -0800 Subject: [PATCH 1/4] ci: Configure build and deployment of site --- .github/workflows/README.md | 14 +++++ .github/workflows/ci.yml | 110 ++++++++++++++++++------------------ .github/workflows/site.yml | 51 +++++++++++++++++ 3 files changed, 120 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/site.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..f0e7f43 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,14 @@ +# GitHub Actions for Dewy + +We currently have 3 workflows: + +1. `ci.yml` defines the CI process for the core service and clients. +2. `lint-pr.yml` defines linting of the PR itself (comments, etc.). +3. `site.yml` defines the build and deployment process for the site. + +## Future Improvements + +1. Release drafting / publishing. +2. Assign labels to PRs based on directories touched (eg., `docs`, `service`, etc.) and + conventional commit (`fix`, `feature`, etc.). +3. Require conditional checks https://github.com/marketplace/actions/require-conditional-status-checks \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be16a07..aa79cbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,64 +1,64 @@ name: CI on: - push: - branches: - - master - pull_request: + push: + branches: + - master + pull_request: concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - python_test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Python - uses: actions/setup-python@v4 - # see details (matrix, python-version, python-version-file, etc.) - # https://github.com/actions/setup-python - with: - python-version: '3.11' - - name: Install poetry - uses: abatilo/actions-poetry@v2 - - name: Setup a local virtual environment (if no poetry.toml file) - run: | - poetry config virtualenvs.create true --local - poetry config virtualenvs.in-project true --local - - uses: actions/cache@v3 - name: Define a cache for the virtual environment based on the dependencies lock file - with: - path: ./.venv - key: venv-${{ hashFiles('poetry.lock') }} - - name: Install the project dependencies - run: poetry install --with=dev - - name: pytest - run: poetry run pytest -v - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - - name: check openapi client up to date - run: | - poetry run poe extract-openapi - poetry run poe update-client - # Record intent to add any new files in client - git add -N dewy-client - # Diff, and report any changes (including any new files in dewy-client) - git diff --exit-code + python_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Python + uses: actions/setup-python@v4 + # see details (matrix, python-version, python-version-file, etc.) + # https://github.com/actions/setup-python + with: + python-version: '3.11' + - name: Install poetry + uses: abatilo/actions-poetry@v2 + - name: Setup a local virtual environment (if no poetry.toml file) + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + - uses: actions/cache@v3 + name: Define a cache for the virtual environment based on the dependencies lock file + with: + path: ./.venv + key: venv-${{ hashFiles('poetry.lock') }} + - name: Install the project dependencies + run: poetry install --with=dev + - name: pytest + run: poetry run pytest -v + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + - name: check openapi client up to date + run: | + poetry run poe extract-openapi + poetry run poe update-client + # Record intent to add any new files in client + git add -N dewy-client + # Diff, and report any changes (including any new files in dewy-client) + git diff --exit-code - python_lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Ruff Lint - uses: chartboost/ruff-action@v1 + python_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Ruff Lint + uses: chartboost/ruff-action@v1 - python_format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Ruff Format (Check) - uses: chartboost/ruff-action@v1 - with: - args: format --check \ No newline at end of file + python_format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Ruff Format (Check) + uses: chartboost/ruff-action@v1 + with: + args: format --check \ No newline at end of file diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml new file mode 100644 index 0000000..171d153 --- /dev/null +++ b/.github/workflows/site.yml @@ -0,0 +1,51 @@ +name: Deploy Site to GitHub Pages + +on: + push: + branches: + - main + paths: + - 'docs/**' + pull_request: + paths: + - 'docs/**' + +permissions: + contents: write + +jobs: + deploy: + name: Build and (maybe) Deploy Site + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: yarn + + - name: Install dependencies + run: yarn install --frozen-lockfile + - name: Build website + run: yarn build + + # Popular action to deploy to GitHub Pages: + # Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + # Only run on push to main. + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # Build output to publish to the `gh-pages` branch: + publish_dir: ./build + # The following lines assign commit authorship to the official + # GH-Actions bot for deploys to `gh-pages` branch: + # https://github.com/actions/checkout/issues/13#issuecomment-724415212 + # The GH actions bot is used by default if you didn't specify the two fields. + # You can swap them out with your own user credentials. + user_name: github-actions[bot] + user_email: 41898282+github-actions[bot]@users.noreply.github.com \ No newline at end of file From ecc5fb8ffed8df82728c07cd104dd809f9045d41 Mon Sep 17 00:00:00 2001 From: Ben Chambers <35960+bjchambers@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:10:46 -0800 Subject: [PATCH 2/4] also trigger on workflow changes --- .github/workflows/site.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index 171d153..020dd60 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -6,9 +6,11 @@ on: - main paths: - 'docs/**' + - '.github/workflows/site.yml' pull_request: paths: - 'docs/**' + - '.github/workflows/site.yml' permissions: contents: write From 5a87535aaf4a95baae71209fc177581c61f4deae Mon Sep 17 00:00:00 2001 From: Ben Chambers <35960+bjchambers@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:14:02 -0800 Subject: [PATCH 3/4] fix caching --- .github/workflows/site.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index 020dd60..038286f 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -1,4 +1,4 @@ -name: Deploy Site to GitHub Pages +name: Site on: push: @@ -28,6 +28,7 @@ jobs: with: node-version: 18 cache: yarn + cache-dependency-path: docs/package-lock.json - name: Install dependencies run: yarn install --frozen-lockfile From 939eed94a727a1449a300e1c3f1ff2edd816d4b2 Mon Sep 17 00:00:00 2001 From: Ben Chambers <35960+bjchambers@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:15:18 -0800 Subject: [PATCH 4/4] fix working directory --- .github/workflows/site.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index 038286f..d737eab 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -32,8 +32,10 @@ jobs: - name: Install dependencies run: yarn install --frozen-lockfile + working-directory: docs - name: Build website run: yarn build + working-directory: docs # Popular action to deploy to GitHub Pages: # Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus @@ -44,7 +46,7 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} # Build output to publish to the `gh-pages` branch: - publish_dir: ./build + publish_dir: ./docs/build # The following lines assign commit authorship to the official # GH-Actions bot for deploys to `gh-pages` branch: # https://github.com/actions/checkout/issues/13#issuecomment-724415212