From 850087338788a5c647269525d8ba69bd5a3bd646 Mon Sep 17 00:00:00 2001 From: Aleksana <42209822+Aleksanaa@users.noreply.github.com> Date: Mon, 15 Aug 2022 11:14:41 +0800 Subject: [PATCH 1/3] add release workflow --- .github/workflows/release.yml | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..a09298560 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,109 @@ +name: release +on: + push: + branches: + - "release/*" + +jobs: + testing: + name: testing release + runs-on: ubuntu-latest + if: ${{ !startsWith(github.event.head_commit.message,'release') }} + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Get tags + run: git fetch --all --tags + + - name: Get version + run: | + BRANCH=$(git symbolic-ref --short HEAD) + VER=${BRANCH#*release/} + if [[ $(git tag | grep ${VER}rc) ]];then + TAGS=$(git tag | grep ${VER}rc | awk 'END {print}') + REL=${TAGS##*rc} + let REL++ + else + REL=1 + fi + echo "BUILDVER=${VER}rc${REL}" >> $GITHUB_ENV + + - name: Update versions + run: | + sed -i "/^ *VERSION = /cVERSION = '${{ env.BUILDVER }}'" hyfetch/constants.py + + - name: Making tags + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git stage . + git commit -m "tagged unstable ${{ env.BUILDVER }}" + git tag --force ${{ env.BUILDVER }} + + - name: Upload changes + run: | + git pull && git push && git push --tags + + - name: Deploy to PYPI + uses: casperdcl/deploy-pypi@v2 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + pip: wheel -w dist/ --no-deps . + + release: + name: formal release + runs-on: ubuntu-latest + if: ${{ startsWith(github.event.head_commit.message,'release') }} + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get version + run: | + BRANCH=$(git symbolic-ref --short HEAD) + echo "BUILDVER=${BRANCH#*release/}" >> $GITHUB_ENV + + - name: Update package.json + uses: jossef/action-set-json-field@v2 + with: + file: package.json + field: version + value: ${{ env.BUILDVER }} + + - name: Update neofetch version + run: | + REVISION=$(expr $(git rev-list --count HEAD neofetch) - 2902) + sed -i "/^ *version=/cversion=7.4.0r${REVISION}" neofetch + + - name: Update other versions + run: | + sed -i "/^ *VERSION = /cVERSION = '${{ env.BUILDVER }}'" hyfetch/constants.py + sed -i "/^ *### Unpublished/c### ${{ env.BUILDVER }}" README.md + + - name: Make final tags + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git stage . && git commit -m "tagged stable ${{ env.BUILDVER }}" + git tag --force ${{ env.BUILDVER }} + + - name: Merge branch and push + run: | + git checkout master + git merge release/${{ env.BUILDVER }} --allow-unrelated-histories + git pull && git push && git push --tags + + - name: Generate changelog from README + run: (sed '0,/^ *### ${{ env.BUILDVER }}/d;/^ *#/,$d' temp_CHANGELOG.md + + - name: Publish release + uses: ncipollo/release-action@v1 + with: + bodyFile: "temp_CHANGELOG.md" + tag: ${{ env.BUILDVER }} + token: ${{ secrets.GITHUB_API_TOKEN }} From dd944cb5a577969df1b90c63bd00a14bfa0655f2 Mon Sep 17 00:00:00 2001 From: Aleksana <42209822+Aleksanaa@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:11:10 +0800 Subject: [PATCH 2/3] add some magic to merge to parent branch This commit make it merge to parent branch instead of `master` branch, i.e. you are working on a branch called `refactor` and making a branch `release/2.0`, changes will be applied to `refactor` instead of `master`. --- .github/workflows/release.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a09298560..197dcdc6b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,7 +94,13 @@ jobs: - name: Merge branch and push run: | - git checkout master + parent=$(git show-branch \ + | grep -F '*' \ + | grep -v "$(git rev-parse --abbrev-ref HEAD)" \ + | head -n1 \ + | sed 's/.*\[\(.*\)\].*/\1/' \ + | sed 's/[\^~].*//') + git checkout ${parent} git merge release/${{ env.BUILDVER }} --allow-unrelated-histories git pull && git push && git push --tags From d3377f5cf337c3aa483b60e91897ac6da9dfaa98 Mon Sep 17 00:00:00 2001 From: Aleksana <42209822+Aleksanaa@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:14:06 +0800 Subject: [PATCH 3/3] add --all add --all so final commit to release branch will also update --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 197dcdc6b..1bed25a1b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,7 +102,7 @@ jobs: | sed 's/[\^~].*//') git checkout ${parent} git merge release/${{ env.BUILDVER }} --allow-unrelated-histories - git pull && git push && git push --tags + git pull --all && git push --all && git push --tags - name: Generate changelog from README run: (sed '0,/^ *### ${{ env.BUILDVER }}/d;/^ *#/,$d' temp_CHANGELOG.md