Skip to content

Commit 7001528

Browse files
Fix failing deploy pipeline if release branch does not yet exist
1 parent e0f7d2e commit 7001528

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ jobs:
7676
cat changelog.json
7777
DESIRED_BRANCH="release/${LATEST_CHANGELOG_VERSION}"
7878
echo "DESIRED_BRANCH: ${DESIRED_BRANCH}"
79+
set +e
7980
git ls-remote \
8081
--exit-code \
8182
--heads \
8283
origin ${DESIRED_BRANCH} >/dev/null 2>&1
8384
EXIT_CODE=$?
85+
set -e
8486
echo "EXIT_CODE: ${EXIT_CODE}"
8587
if [[ ${EXIT_CODE} == '0' ]]; then
8688
echo "Git branch '${DESIRED_BRANCH}' exists on remote"

.github/workflows/test-release.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,43 @@ jobs:
7373
name: dist_repo.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
7474
path: dist/*.tar.gz
7575
retention-days: 14
76+
- name: Test creation of release branch
77+
run: |
78+
git config user.name "github-actions"
79+
git config user.email "github-actions@github.com"
80+
LATEST_CHANGELOG_VERSION=$(jq -r '.info.version' changelog.json)
81+
echo "LATEST_CHANGELOG_VERSION: ${LATEST_CHANGELOG_VERSION}"
82+
echo "changelog.json file:"
83+
cat changelog.json
84+
DESIRED_BRANCH="release/${LATEST_CHANGELOG_VERSION}"
85+
echo "DESIRED_BRANCH: ${DESIRED_BRANCH}"
86+
set +e
87+
git ls-remote \
88+
--exit-code \
89+
--heads \
90+
origin ${DESIRED_BRANCH} >/dev/null 2>&1
91+
EXIT_CODE=$?
92+
set -e
93+
echo "EXIT_CODE: ${EXIT_CODE}"
94+
if [[ ${EXIT_CODE} == '0' ]]; then
95+
echo "Git branch '${DESIRED_BRANCH}' exists on remote"
96+
git checkout release/${LATEST_CHANGELOG_VERSION}
97+
elif [[ ${EXIT_CODE} == '2' ]]; then
98+
echo "Git branch '${DESIRED_BRANCH}' does not exist on remote"
99+
git checkout -b release/${LATEST_CHANGELOG_VERSION}
100+
fi
101+
git diff > diff.log
102+
echo "Diff in repo"
103+
cat diff.log
104+
if [[ $(git status --porcelain --untracked-files=no | wc -l) -gt 0 ]]; then
105+
echo "changed files available"
106+
git add package.json changelog.md be_upy_blink/version.py
107+
git status
108+
git commit -m "chore: files for release ${LATEST_CHANGELOG_VERSION}"
109+
git push -u origin release/${LATEST_CHANGELOG_VERSION}
110+
else
111+
echo "nothing new to commit and push"
112+
fi
76113
- name: Publish package
77114
uses: pypa/gh-action-pypi-publish@release/v1.13
78115
with:

0 commit comments

Comments
 (0)