From 0fac3afe6cffad52142509c452d26ee37f346318 Mon Sep 17 00:00:00 2001 From: Anders Liland <8539036+andersliland@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:05:26 +0100 Subject: [PATCH 1/2] ci: release with release please --- .github/workflows/lint-pr-title.yml | 20 +++ .github/workflows/release-please.yml | 33 +++++ .../workflows/release-upload-artifacts.yml | 133 ++++++++++++++++++ .pre-commit-config.yaml | 11 ++ .release-please-manifest.json | 3 + CONTRIBUTING.md | 21 +++ commitlint.config.js | 6 + release-please-config.json | 15 ++ 8 files changed, 242 insertions(+) create mode 100644 .github/workflows/lint-pr-title.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .github/workflows/release-upload-artifacts.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .release-please-manifest.json create mode 100644 CONTRIBUTING.md create mode 100644 commitlint.config.js create mode 100644 release-please-config.json diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 0000000..45b45d3 --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,20 @@ +name: "[lint] Commit is conventional" + +on: + pull_request_target: + types: + - edited + - opened + - ready_for_review + - reopened + - synchronize + +permissions: + contents: read + id-token: write + pull-requests: write + +jobs: + lint: + name: Lint + uses: kolonialno/actions/.github/workflows/pr-conventional-commit.yml@main diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..3623916 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,33 @@ +--- +name: "[release] Please" + +on: + workflow_dispatch: + push: + branches: + - main + - ci/test-release-please** + +permissions: + id-token: write + contents: write + pull-requests: write + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: google-github-actions/release-please-action@v4 + id: release + with: + # When you use the repository's GITHUB_TOKEN to perform tasks, events such as 'on.release' + # use in the Upload artifacts workflow wont be triggered. + # This prevents you from accidentally creating recursive workflow runs. + # We needed to use either a PAT og a GitHub App. + # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow + token: ${{ secrets.TIENDABOT_ACCESS_TOKEN }} + config-file: release-please-config.json + manifest-file: .release-please-manifest.json diff --git a/.github/workflows/release-upload-artifacts.yml b/.github/workflows/release-upload-artifacts.yml new file mode 100644 index 0000000..f70dadb --- /dev/null +++ b/.github/workflows/release-upload-artifacts.yml @@ -0,0 +1,133 @@ +--- +name: "[release] Upload artifacts" + +on: + # Manually triggering this from main branch + # will upload artifacts to current release. + workflow_dispatch: + inputs: + tag: + type: string + description: Tag to checkout. View tags at https://github.com/kolonialno/troncos/tags + default: "" + push: + branches: + - release-test-** + release: + types: + # Trigger on creation of a draft is not possible + # https://github.com/orgs/community/discussions/7118 + # ref https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release + # This will trigger when a pre-release is created, but not when published. + - prereleased + +permissions: + id-token: write + contents: write + pull-requests: write + +env: + PYPI_TOKEN: "${{ secrets.PYPI_TOKEN }}" + +jobs: + tag: + runs-on: ubuntu-latest + name: Tag on commit + outputs: + upload: ${{ steps.tag.outputs.upload }} + tag: ${{ steps.tag.outputs.tag }} + steps: + - name: Checkout + uses: actions/checkout@v4 + if: ${{ github.event.inputs.tag == '' }} + + - name: Checkout tag (workflow_dispatch) + uses: actions/checkout@v4 + if: ${{ github.event.inputs.tag != '' }} + with: + ref: ${{ github.event.inputs.tag }} + + - name: Read .tool-versions + uses: marocchino/tool-versions-action@v1 + id: versions + + - name: Setup Python + uses: ./.github/actions/setup-python + with: + python-version: ${{ steps.versions.outputs.python }} + poetry-version: ${{ steps.versions.outputs.poetry }} + + # Only upload if current commit has a tag that match the version in + # Pyproject. This will only be the case for a troncos tag that has format + # x.y.z + # The other releases have component name prefixed. Eaxmple: component-x.y.z. + - name: Verify semVer tag on commit + id: tag + run: | + set -ex + if [ "${{ github.event.inputs.tag }}" == '' ]; then + + tag=$(git tag --points-at ${{ github.sha }}) + echo tag=$tag + echo "tag=$tag" >> $GITHUB_OUTPUT; + + project_version=$(poetry version -s) + echo project_version=$project_version + + if [ "$tag" == "$project_version" ]; then + echo "upload=true" >> $GITHUB_OUTPUT; + else + echo "upload=false" >> $GITHUB_OUTPUT; + fi + else + echo "upload=true" >> $GITHUB_OUTPUT; + fi + + python_package: + runs-on: ubuntu-latest + name: Python package + needs: tag + steps: + - name: Checkout + uses: actions/checkout@v4 + if: ${{ github.event.inputs.tag == '' }} + + - name: Checkout tag (workflow_dispatch) + uses: actions/checkout@v4 + if: ${{ github.event.inputs.tag != '' }} + with: + ref: ${{ github.event.inputs.tag }} + + - name: Read .tool-versions + uses: marocchino/tool-versions-action@v1 + id: versions + + - name: Setup Python + uses: ./.github/actions/setup-python + with: + python-version: ${{ steps.versions.outputs.python }} + poetry-version: ${{ steps.versions.outputs.poetry }} + + - name: Publish Troncos Python package + if: ${{ needs.tag.outputs.upload == 'true' }} + run: | + set -ex + make release + + publish: + runs-on: ubuntu-latest + name: Publish + needs: + - python_package + - tag + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Publish pre-release + if: ${{ needs.tag.outputs.upload == 'true' }} + run: | + set -ex + gh release edit ${{ needs.tag.outputs.tag }} --prerelease=false --latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..13ce2bf --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +--- +default_install_hook_types: [pre-commit, commit-msg] +repos: +- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: "v9.11.0" + hooks: + - id: commitlint + stages: [commit-msg] + additional_dependencies: ["@commitlint/config-conventional"] + args: + - "--config=commitlint.config.js" diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..2276f3d --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "4.3.1" +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b56d51e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,21 @@ +# CONTRIBUTING + +## Set-up + +```shell +pre-commit install +poetry install +``` + +## Release + +We use [release-please](https://github.com/googleapis/release-please) to automate release including semver version based on [conventional-commits](https://www.conventionalcommits.org/en/v1.0.0/). + +Manually create a release PR from main branch + +```bash +release-please release-pr \ +--token=$(gh auth token) \ +--repo-url=kolonialno/troncos +--dry-run +``` diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..362c11b --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + extends: ["@commitlint/config-conventional"], + rules: { + "footer-max-line-length": [0, "always"], // ignore rule + }, +}; diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..8a149cb --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "bootstrap-sha": "3c032c809f68f677d12fdac5557351cde40bffd7", + "include-v-in-tag": false, + "separate-pull-requests": true, + "prerelease": true, + "packages": { + ".": { + "component": "troncos", + "bump-minor-pre-major": true, + "include-component-in-tag": false, + "release-type": "python" + } + } +} From 69ec62ca95c3e2eaa9018a8ee709d1f989928c46 Mon Sep 17 00:00:00 2001 From: Anders Liland <8539036+andersliland@users.noreply.github.com> Date: Mon, 5 Feb 2024 09:03:48 +0100 Subject: [PATCH 2/2] ci: dont need seperate upload workflow --- .github/workflows/release-please.yml | 7 +- .../workflows/release-upload-artifacts.yml | 133 ------------------ .release-please-manifest.json | 2 +- CONTRIBUTING.md | 1 + release-please-config.json | 2 +- 5 files changed, 4 insertions(+), 141 deletions(-) delete mode 100644 .github/workflows/release-upload-artifacts.yml diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 3623916..797fe8a 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -23,11 +23,6 @@ jobs: - uses: google-github-actions/release-please-action@v4 id: release with: - # When you use the repository's GITHUB_TOKEN to perform tasks, events such as 'on.release' - # use in the Upload artifacts workflow wont be triggered. - # This prevents you from accidentally creating recursive workflow runs. - # We needed to use either a PAT og a GitHub App. - # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow - token: ${{ secrets.TIENDABOT_ACCESS_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} config-file: release-please-config.json manifest-file: .release-please-manifest.json diff --git a/.github/workflows/release-upload-artifacts.yml b/.github/workflows/release-upload-artifacts.yml deleted file mode 100644 index f70dadb..0000000 --- a/.github/workflows/release-upload-artifacts.yml +++ /dev/null @@ -1,133 +0,0 @@ ---- -name: "[release] Upload artifacts" - -on: - # Manually triggering this from main branch - # will upload artifacts to current release. - workflow_dispatch: - inputs: - tag: - type: string - description: Tag to checkout. View tags at https://github.com/kolonialno/troncos/tags - default: "" - push: - branches: - - release-test-** - release: - types: - # Trigger on creation of a draft is not possible - # https://github.com/orgs/community/discussions/7118 - # ref https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release - # This will trigger when a pre-release is created, but not when published. - - prereleased - -permissions: - id-token: write - contents: write - pull-requests: write - -env: - PYPI_TOKEN: "${{ secrets.PYPI_TOKEN }}" - -jobs: - tag: - runs-on: ubuntu-latest - name: Tag on commit - outputs: - upload: ${{ steps.tag.outputs.upload }} - tag: ${{ steps.tag.outputs.tag }} - steps: - - name: Checkout - uses: actions/checkout@v4 - if: ${{ github.event.inputs.tag == '' }} - - - name: Checkout tag (workflow_dispatch) - uses: actions/checkout@v4 - if: ${{ github.event.inputs.tag != '' }} - with: - ref: ${{ github.event.inputs.tag }} - - - name: Read .tool-versions - uses: marocchino/tool-versions-action@v1 - id: versions - - - name: Setup Python - uses: ./.github/actions/setup-python - with: - python-version: ${{ steps.versions.outputs.python }} - poetry-version: ${{ steps.versions.outputs.poetry }} - - # Only upload if current commit has a tag that match the version in - # Pyproject. This will only be the case for a troncos tag that has format - # x.y.z - # The other releases have component name prefixed. Eaxmple: component-x.y.z. - - name: Verify semVer tag on commit - id: tag - run: | - set -ex - if [ "${{ github.event.inputs.tag }}" == '' ]; then - - tag=$(git tag --points-at ${{ github.sha }}) - echo tag=$tag - echo "tag=$tag" >> $GITHUB_OUTPUT; - - project_version=$(poetry version -s) - echo project_version=$project_version - - if [ "$tag" == "$project_version" ]; then - echo "upload=true" >> $GITHUB_OUTPUT; - else - echo "upload=false" >> $GITHUB_OUTPUT; - fi - else - echo "upload=true" >> $GITHUB_OUTPUT; - fi - - python_package: - runs-on: ubuntu-latest - name: Python package - needs: tag - steps: - - name: Checkout - uses: actions/checkout@v4 - if: ${{ github.event.inputs.tag == '' }} - - - name: Checkout tag (workflow_dispatch) - uses: actions/checkout@v4 - if: ${{ github.event.inputs.tag != '' }} - with: - ref: ${{ github.event.inputs.tag }} - - - name: Read .tool-versions - uses: marocchino/tool-versions-action@v1 - id: versions - - - name: Setup Python - uses: ./.github/actions/setup-python - with: - python-version: ${{ steps.versions.outputs.python }} - poetry-version: ${{ steps.versions.outputs.poetry }} - - - name: Publish Troncos Python package - if: ${{ needs.tag.outputs.upload == 'true' }} - run: | - set -ex - make release - - publish: - runs-on: ubuntu-latest - name: Publish - needs: - - python_package - - tag - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Publish pre-release - if: ${{ needs.tag.outputs.upload == 'true' }} - run: | - set -ex - gh release edit ${{ needs.tag.outputs.tag }} --prerelease=false --latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2276f3d..f4b3cc5 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.3.1" + ".": "4.4.1" } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b56d51e..688c611 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,4 @@ + # CONTRIBUTING ## Set-up diff --git a/release-please-config.json b/release-please-config.json index 8a149cb..f0bb91a 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", - "bootstrap-sha": "3c032c809f68f677d12fdac5557351cde40bffd7", + "bootstrap-sha": "8ed4b839a6c7808f551baea9284eb7e36be7ef58", "include-v-in-tag": false, "separate-pull-requests": true, "prerelease": true,