From 97efc114a06154027ab005d64f985ee7fb8c13b9 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 15 Aug 2024 15:27:36 +0000 Subject: [PATCH 1/4] ci: make Python QA reusable --- .github/workflows/python-publish.yml | 40 ++++------------------- .github/workflows/python-pull-request.yml | 23 +++++++++++++ CHANGELOG.md | 1 + 3 files changed, 31 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/python-pull-request.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index b6950b2b..2cb554a0 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -4,48 +4,22 @@ name: Upload Python Package on: - - push: {} - pull_request: release: types: [created] jobs: quality: - name: Code QA - runs-on: ubuntu-latest - steps: - - run: sudo apt-get install -y pandoc # Needed by sphinx for notebooks - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: 3.x - - uses: pre-commit/action@v3.0.1 + uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-precommit-run.yml@v2 + with: + skip-hooks: "no-commit-to-branch" checks: strategy: - fail-fast: false matrix: - platform: ["ubuntu-latest", "macos-latest"] - python-version: ["3.10"] - - name: Python ${{ matrix.python-version }} on ${{ matrix.platform }} - runs-on: ${{ matrix.platform }} - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install - run: | - pip install -e .[all,tests] - pip freeze - - - name: Tests - run: pytest + python-version: ["3.9", "3.10"] + uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-pytest-pyproject.yml@v2 + with: + python-version: ${{ matrix.python-version }} deploy: needs: [checks, quality] diff --git a/.github/workflows/python-pull-request.yml b/.github/workflows/python-pull-request.yml new file mode 100644 index 00000000..0ebecb13 --- /dev/null +++ b/.github/workflows/python-pull-request.yml @@ -0,0 +1,23 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Code Quality checks for PRs + +on: + push: + pull_request_target: + types: [opened, synchronize, reopened] + +jobs: + quality: + uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-precommit-run.yml@v2 + with: + skip-hooks: "no-commit-to-branch" + + checks: + strategy: + matrix: + python-version: ["3.9", "3.10"] + uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-pytest-pyproject.yml@v2 + with: + python-version: ${{ matrix.python-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index c1e9db21..e4e22a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Keep it human-readable, your future self will thank you! - Pinned numpy<2 until we can test all migration - (ci): path ignore of docs for downstream ci - (ci): remove yaml anchor, unsupported by Github + - ci: make python QA reusable ### Removed - Dependency on mlflow-export-import From 303bd5c31124542393067fca47201a7cfe5753f7 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Thu, 15 Aug 2024 15:30:32 +0000 Subject: [PATCH 2/4] ci: changelog updater --- .../workflows/changelog-release-update.yml | 23 ++++++++++--------- CHANGELOG.md | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/changelog-release-update.yml b/.github/workflows/changelog-release-update.yml index c44f46ad..056c95fb 100644 --- a/.github/workflows/changelog-release-update.yml +++ b/.github/workflows/changelog-release-update.yml @@ -5,16 +5,14 @@ on: release: types: [released] +permissions: + pull-requests: write + contents: write + jobs: update: runs-on: ubuntu-latest - permissions: - # Give the default GITHUB_TOKEN write permission to commit and push the - # updated CHANGELOG back to the repository. - # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ - contents: write - steps: - name: Checkout code uses: actions/checkout@v4 @@ -28,9 +26,12 @@ jobs: heading-text: ${{ github.event.release.name }} release-notes: ${{ github.event.release.body }} - - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v5 + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 with: - branch: ${{ github.event.release.target_commitish }} - commit_message: Update CHANGELOG - file_pattern: CHANGELOG.md + branch: docs/changelog-update-${{ github.event.release.tag_name }} + title: '[Changelog] Update to ${{ github.event.release.tag_name }}' + labels: | + automated pr + add-paths: | + CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e22a48..1ec705c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Keep it human-readable, your future self will thank you! - (ci): path ignore of docs for downstream ci - (ci): remove yaml anchor, unsupported by Github - ci: make python QA reusable + - ci: permissions on changelog updater ### Removed - Dependency on mlflow-export-import From 34b1f65311f01eacad44f5829d358eab3eaaeb6a Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Fri, 16 Aug 2024 17:14:18 +0200 Subject: [PATCH 3/4] ci: py 3.x for now --- .github/workflows/python-publish.yml | 6 +----- .github/workflows/python-pull-request.yml | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 2cb554a0..db316803 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,3 +1,4 @@ +--- # This workflow will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries @@ -14,12 +15,7 @@ jobs: skip-hooks: "no-commit-to-branch" checks: - strategy: - matrix: - python-version: ["3.9", "3.10"] uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-pytest-pyproject.yml@v2 - with: - python-version: ${{ matrix.python-version }} deploy: needs: [checks, quality] diff --git a/.github/workflows/python-pull-request.yml b/.github/workflows/python-pull-request.yml index 0ebecb13..9145d54a 100644 --- a/.github/workflows/python-pull-request.yml +++ b/.github/workflows/python-pull-request.yml @@ -1,3 +1,4 @@ +--- # This workflow will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries @@ -15,9 +16,4 @@ jobs: skip-hooks: "no-commit-to-branch" checks: - strategy: - matrix: - python-version: ["3.9", "3.10"] uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-pytest-pyproject.yml@v2 - with: - python-version: ${{ matrix.python-version }} From 77c79677809fe2751ca4b4c3e52c01630e182bcf Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Fri, 16 Aug 2024 17:19:10 +0200 Subject: [PATCH 4/4] ci: remove duplication --- .../workflows/changelog-release-update.yml | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/changelog-release-update.yml b/.github/workflows/changelog-release-update.yml index 056c95fb..a31c06e8 100644 --- a/.github/workflows/changelog-release-update.yml +++ b/.github/workflows/changelog-release-update.yml @@ -1,3 +1,4 @@ +--- # .github/workflows/update-changelog.yaml name: "Update Changelog" @@ -14,24 +15,21 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.event.release.target_commitish }} + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.target_commitish }} - - name: Update Changelog - uses: stefanzweifel/changelog-updater-action@v1 - with: - latest-version: ${{ github.event.release.tag_name }} - heading-text: ${{ github.event.release.name }} - release-notes: ${{ github.event.release.body }} + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.tag_name }} + heading-text: ${{ github.event.release.name }} - - name: Create Pull Request - uses: peter-evans/create-pull-request@v6 - with: - branch: docs/changelog-update-${{ github.event.release.tag_name }} - title: '[Changelog] Update to ${{ github.event.release.tag_name }}' - labels: | - automated pr - add-paths: | - CHANGELOG.md + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + branch: docs/changelog-update-${{ github.event.release.tag_name }} + title: '[Changelog] Update to ${{ github.event.release.tag_name }}' + add-paths: | + CHANGELOG.md