Skip to content

Commit 18ea910

Browse files
authored
Merge pull request #279 from david-cermak/feat/auto_tag
ci(common): Support for tagging and releasing in CI
2 parents b0d3b41 + 62be981 commit 18ea910

File tree

6 files changed

+116
-30
lines changed

6 files changed

+116
-30
lines changed

.github/workflows/pre_commit_check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ jobs:
1515
uses: actions/checkout@v3
1616
with:
1717
ref: ${{ github.base_ref }}
18+
fetch-depth: 20
1819
- name: Fetch head and base refs
1920
# This is necessary for pre-commit to check the changes in the PR branch (and to set origin/HEAD and HEAD refs)
2021
run: |
2122
git fetch origin ${{ github.event.pull_request.head.sha }}:pr_ref
2223
git checkout pr_ref
2324
git remote set-head origin --auto
25+
git merge-base origin/HEAD HEAD || ( echo "Your PR is far behind origin/HEAD, please rebase" && exit 1 )
2426
- name: Set up Python environment
2527
uses: actions/setup-python@master
2628
with:

.github/workflows/publish-docs-component.yml

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,57 @@ env:
1313
DOCS_DEPLOY_PATH : ${{ secrets.DOCS_DEPLOY_PATH }}
1414

1515
jobs:
16-
docs_build:
17-
name: Docs-Build-And-Upload
16+
publish:
17+
name: Publish Tag, Release, Docs, Component
1818
runs-on: ubuntu-latest
1919
# Skip running on forks since it won't have access to secrets
2020
if: github.repository == 'espressif/esp-protocols'
2121
steps:
2222
- name: Checkout esp-protocols
23-
uses: actions/checkout@master
23+
uses: actions/checkout@v3
2424
with:
2525
persist-credentials: false
2626
fetch-depth: 0
2727
submodules: recursive
28-
- name: Generate docs
28+
token: "${{ secrets.GITHUB_TOKEN }}"
29+
- name: Check for version update
2930
shell: bash
30-
run: |
31-
sudo apt-get update
32-
sudo apt-get -y install doxygen clang python3-pip
33-
python -m pip install breathe recommonmark esp-docs==1.4.1
34-
cd $GITHUB_WORKSPACE/docs
35-
./generate_docs
36-
- name: Deploying generated docs
37-
if: always()
38-
shell: bash
39-
run: |
40-
source $GITHUB_WORKSPACE/docs/utils.sh
41-
add_doc_server_ssh_keys $DOCS_DEPLOY_KEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER
42-
export GIT_VER=$(git describe --always)
43-
export GITHUB_REF_NAME=latest
44-
export DOCS_BUILD_DIR=$GITHUB_WORKSPACE/docs
45-
deploy-docs
46-
- name: Upload components to component service
47-
uses: espressif/github-actions/upload_components@master
31+
run: ./ci/detect_component_bump
32+
- name: Tag merge commit
33+
if: env.BUMP_VERSION != ''
34+
uses: anothrNick/[email protected]
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
CUSTOM_TAG: ${{ env.BUMP_TAG }}
38+
- name: Create Release
39+
if: env.BUMP_VERSION != ''
40+
uses: softprops/action-gh-release@v1
4841
with:
49-
directories: "components/esp_modem;components/esp_websocket_client;components/mdns;components/asio;components/esp_mqtt_cxx"
50-
namespace: "espressif"
51-
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
42+
body_path: "release_notes.md"
43+
tag_name: ${{ env.BUMP_TAG }}
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
# - name: Generate docs
47+
# shell: bash
48+
# run: |
49+
# sudo apt-get update
50+
# sudo apt-get -y install doxygen clang python3-pip
51+
# python -m pip install breathe recommonmark esp-docs==1.4.1
52+
# cd $GITHUB_WORKSPACE/docs
53+
# ./generate_docs
54+
# - name: Deploying generated docs
55+
# if: always()
56+
# shell: bash
57+
# run: |
58+
# source $GITHUB_WORKSPACE/docs/utils.sh
59+
# add_doc_server_ssh_keys $DOCS_DEPLOY_KEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER
60+
# export GIT_VER=$(git describe --always)
61+
# export GITHUB_REF_NAME=latest
62+
# export DOCS_BUILD_DIR=$GITHUB_WORKSPACE/docs
63+
# deploy-docs
64+
# - name: Upload components to component service
65+
# uses: espressif/github-actions/upload_components@master
66+
# with:
67+
# directories: "components/esp_modem;components/esp_websocket_client;components/mdns;components/asio;components/esp_mqtt_cxx"
68+
# namespace: "espressif"
69+
# api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ When releasing a new component version we have to:
2424
* Deploy the component to component registry
2525
* Update the documentation
2626

27-
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:
28-
* Create a branch in this repository (not from fork)
29-
* Run `cz bump [version]` (version number is optional, `cz` would automatically increment it if not present)
30-
* Check the updated `CHANGELOG.md`
31-
* Create and merge the branch to master
27+
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:
28+
* Run `ci/bump [component] [version]` (version number is optional, `cz` would automatically increment it if not present)
29+
* Check the updated `CHANGELOG.md` and the generated bump commit message
30+
* Create a PR
31+
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

ci/bump

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "$1" ]; then
4+
echo "Usage: bump component [version]"
5+
exit 1;
6+
fi
7+
8+
comp=$1; shift;
9+
10+
cd components/${comp}
11+
if ! cz bump --dry-run; then
12+
echo "Commitizen bump commad failed!"
13+
exit 1;
14+
fi
15+
16+
cz_bump_out=`cz bump --files-only "$@"`
17+
commit_title=`echo "${cz_bump_out}" | head -1`
18+
commit_body=`cat ../../release_notes.txt`
19+
20+
git add -u .
21+
git commit -m $"${commit_title}
22+
23+
${commit_body}"

ci/changelog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def main():
9393
updated_changelog.write(orig_items)
9494
git.add(filename)
9595

96+
# write the current changelog entry to a local text file (removing links, captions and extra newlines)
97+
changelog = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', changelog)
98+
changelog = re.sub(r'\#\#[\#\s]*(.+)', r'\1', changelog)
99+
changelog = re.sub(r'\n\n', '\n', changelog)
100+
with open(os.path.join(root_path, 'release_notes.txt'), 'w') as release_notes:
101+
release_notes.write(changelog)
102+
96103

97104
if __name__ == '__main__':
98105
main()

ci/detect_component_bump

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if ! git show -s | grep -q '^Merge'; then
6+
echo "Not a merge commit"
7+
exit 0;
8+
fi
9+
10+
for comp in `ls components`; do
11+
if git log -1 -m --name-only --pretty="" | grep -q components/${comp}/idf_component.yml; then
12+
echo "${comp}: Component version has been updated"
13+
version=`grep version: components/${comp}/.cz.yaml`
14+
version=${version#*version: }
15+
16+
tag_format=`grep tag_format: components/${comp}/.cz.yaml`
17+
tag_format=${tag_format#*tag_format: }
18+
19+
eval tag=$tag_format
20+
21+
# creates release notes from the last entry (between first two "## sections")
22+
awk '/^## \[/{a++};{if(a==1){print}}' components/${comp}/CHANGELOG.md > release_notes.md
23+
24+
echo "BUMP_VERSION=${version}"
25+
echo "BUMP_COMPONENT=${comp}"
26+
echo "BUMP_TAG=${tag}"
27+
28+
# export the findings to github env, so it could be used in other jobs
29+
echo "BUMP_VERSION=${version}" >> "$GITHUB_ENV"
30+
echo "BUMP_COMPONENT=${comp}" >> "$GITHUB_ENV"
31+
echo "BUMP_TAG=${tag}" >> "$GITHUB_ENV"
32+
33+
exit 0;
34+
fi
35+
done
36+
echo "No changes in component version file"

0 commit comments

Comments
 (0)