From 6daf6c6ba63687b907e5e6ff7e054bf388ac198c Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 19 Apr 2023 15:39:35 +0200 Subject: [PATCH] ci(common): Support for tagging and releasing in CI --- .github/workflows/publish-docs-component.yml | 24 +++++++++++-- CONTRIBUTING.md | 10 +++--- ci/bump | 23 +++++++++++++ ci/changelog.py | 7 ++++ ci/detect_component_bump | 36 ++++++++++++++++++++ 5 files changed, 92 insertions(+), 8 deletions(-) create mode 100755 ci/bump create mode 100755 ci/detect_component_bump diff --git a/.github/workflows/publish-docs-component.yml b/.github/workflows/publish-docs-component.yml index ae6390acf..e31fc3783 100644 --- a/.github/workflows/publish-docs-component.yml +++ b/.github/workflows/publish-docs-component.yml @@ -13,18 +13,36 @@ env: DOCS_DEPLOY_PATH : ${{ secrets.DOCS_DEPLOY_PATH }} jobs: - docs_build: - name: Docs-Build-And-Upload + publish: + name: Publish Tag, Release, Docs, Component runs-on: ubuntu-latest # Skip running on forks since it won't have access to secrets if: github.repository == 'espressif/esp-protocols' steps: - name: Checkout esp-protocols - uses: actions/checkout@master + uses: actions/checkout@v3 with: persist-credentials: false fetch-depth: 0 submodules: recursive + token: "${{ secrets.GITHUB_TOKEN }}" + - name: Check for version update + shell: bash + run: ./ci/detect_component_bump + - name: Tag merge commit + if: env.BUMP_VERSION != '' + uses: anothrNick/github-tag-action@1.61.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CUSTOM_TAG: ${{ env.BUMP_TAG }} + - name: Create Release + if: env.BUMP_VERSION != '' + uses: softprops/action-gh-release@v1 + with: + body_path: "release_notes.md" + tag_name: ${{ env.BUMP_TAG }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Generate docs shell: bash run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e325e78a6..5813cc5a1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,8 +24,8 @@ When releasing a new component version we have to: * Deploy the component to component registry * Update the documentation -This process is not fully automated, the first three steps need to be performed manually by project maintainers running the `bump` command (from within this repository, rather than forks, to publish the release `tag`). Release procedure is as follows: -* Create a branch in this repository (not from fork) -* Run `cz bump [version]` (version number is optional, `cz` would automatically increment it if not present) -* Check the updated `CHANGELOG.md` -* Create and merge the branch to master +This process is not fully automated, the first step needs to be performed manually by project maintainers running the `bump` command. Release procedure is as follows: +* Run `ci/bump [component] [version]` (version number is optional, `cz` would automatically increment it if not present) +* Check the updated `CHANGELOG.md` and the generated bump commit message +* Create a PR +Once the PR is merged, the CI job tags the merge commit, creates a new release, builds and deploys documentation and the new component to the component registry diff --git a/ci/bump b/ci/bump new file mode 100755 index 000000000..3af9b1883 --- /dev/null +++ b/ci/bump @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -z "$1" ]; then + echo "Usage: bump component [version]" + exit 1; +fi + +comp=$1; shift; + +cd components/${comp} +if ! cz bump --dry-run; then + echo "Commitizen bump commad failed!" + exit 1; +fi + +cz_bump_out=`cz bump --files-only "$@"` +commit_title=`echo "${cz_bump_out}" | head -1` +commit_body=`cat ../../release_notes.txt` + +git add -u . +git commit -m $"${commit_title} + +${commit_body}" diff --git a/ci/changelog.py b/ci/changelog.py index e51e017e9..f5091c2ce 100644 --- a/ci/changelog.py +++ b/ci/changelog.py @@ -93,6 +93,13 @@ def main(): updated_changelog.write(orig_items) git.add(filename) + # write the current changelog entry to a local text file (removing links, captions and extra newlines) + changelog = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', changelog) + changelog = re.sub(r'\#\#[\#\s]*(.+)', r'\1', changelog) + changelog = re.sub(r'\n\n', '\n', changelog) + with open(os.path.join(root_path, 'release_notes.txt'), 'w') as release_notes: + release_notes.write(changelog) + if __name__ == '__main__': main() diff --git a/ci/detect_component_bump b/ci/detect_component_bump new file mode 100755 index 000000000..e51f24966 --- /dev/null +++ b/ci/detect_component_bump @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +if ! git show -s | grep -q '^Merge'; then + echo "Not a merge commit" + exit 0; +fi + +for comp in `ls components`; do +if git log -1 -m --name-only --pretty="" | grep -q components/${comp}/idf_component.yml; then + echo "${comp}: Component version has been updated" + version=`grep version: components/${comp}/.cz.yaml` + version=${version#*version: } + + tag_format=`grep tag_format: components/${comp}/.cz.yaml` + tag_format=${tag_format#*tag_format: } + + eval tag=$tag_format + + # creates release notes from the last entry (between first two "## sections") + awk '/^## \[/{a++};{if(a==1){print}}' components/${comp}/CHANGELOG.md > release_notes.md + + echo "BUMP_VERSION=${version}" + echo "BUMP_COMPONENT=${comp}" + echo "BUMP_TAG=${tag}" + + # export the findings to github env, so it could be used in other jobs + echo "BUMP_VERSION=${version}" >> "$GITHUB_ENV" + echo "BUMP_COMPONENT=${comp}" >> "$GITHUB_ENV" + echo "BUMP_TAG=${tag}" >> "$GITHUB_ENV" + + exit 0; +fi +done +echo "No changes in component version file"