Skip to content

Commit d0c65e6

Browse files
committed
Always restart release if it exists
1 parent 896951c commit d0c65e6

1 file changed

Lines changed: 20 additions & 41 deletions

File tree

.github/workflows/prepare-release.yml

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,30 @@ jobs:
5353
fi
5454
fi
5555
56-
if [[ -z $(git ls-remote --heads origin rc/$RELEASE_VERSION) ]]; then
57-
echo "Release branch rc/$RELEASE_VERSION does not exist."
58-
echo "create_release_branch=true" >> "$GITHUB_ENV"
59-
echo "create_release_pr=true" >> "$GITHUB_ENV"
60-
echo "create_release_feature_branch=true" >> "$GITHUB_ENV"
61-
else
62-
echo "Release branch rc/$RELEASE_VERSION already exists."
63-
echo "create_release_branch=false" >> "$GITHUB_ENV"
56+
release_pr=$(gh pr view rc/$RELEASE_VERSION --json title,state,number)
6457
65-
if [[ -z $(git ls-remote --heads origin feature/update-user-manual-for-$RELEASE_VERSION) ]]; then
66-
echo "Feature branch feature/update-user-manual-for-$RELEASE_VERSION does not exist."
67-
echo "create_release_feature_branch=true" >> "$GITHUB_ENV"
68-
else
69-
echo "Feature branch feature/update-user-manual-for-$RELEASE_VERSION already exists."
70-
echo "create_release_feature_branch=false" >> "$GITHUB_ENV"
71-
fi
58+
if [[ ! -z "$release_pr" ]]; then
7259
73-
pr_state=$(gh pr view rc/$RELEASE_VERSION --json title,state)
74-
pr_title=$(echo "$pr_state" | jq -r '.title')
75-
pr_state=$(echo "$pr_state" | jq -r '.state')
60+
pr_title=$(echo "$release_pr" | jq -r '.title')
61+
pr_state=$(echo "$release_pr" | jq -r '.state')
62+
pr_number=$(echo "$release_pr" | jq -r '.number')
7663
7764
echo "Found PR '$pr_title' with state '$pr_state'"
7865
79-
if [[ "$pr_title" == "Release v$RELEASE_VERSION" ]] && [[ "$pr_state" == "OPEN" ]]; then
80-
echo "Release PR for rc/$RELEASE_VERSION already exists and is open."
81-
echo "create_release_pr=false" >> "$GITHUB_ENV"
82-
else
83-
echo "Release PR for rc/$RELEASE_VERSION does not exist or is closed."
84-
echo "create_release_pr=true" >> "$GITHUB_ENV"
66+
if [[ "$pr_title" == "Release v$RELEASE_VERSION" ]] && [[ "$pr_state" != "CLOSED" ]]; then
67+
echo "Release PR is not closed, deleting it to proceed"
68+
gh pr close --delete-branch $pr_number
8569
fi
70+
fi
8671
72+
if [[ ! -z $(git ls-remote --heads origin rc/$RELEASE_VERSION) ]]; then
73+
echo "Deleting existing release branch"
74+
git push origin --delete rc/$RELEASE_VERSION
75+
fi
76+
77+
if [[ ! -z $(git ls-remote --heads origin feature/update-user-manual-for-$RELEASE_VERSION) ]]; then
78+
echo "Deleting existing feature branch"
79+
git push origin --delete feature/update-user-manual-for-$RELEASE_VERSION
8780
fi
8881
8982
- name: Configure git
@@ -104,7 +97,6 @@ jobs:
10497
python scripts/release/validate-version.py "$RELEASE_VERSION"
10598
10699
- name: Create release branch
107-
if: env.create_release_branch == 'true'
108100
run: |
109101
git switch -c rc/$RELEASE_VERSION
110102
git push --set-upstream origin rc/$RELEASE_VERSION
@@ -123,36 +115,23 @@ jobs:
123115
$RELEASE_VERSION
124116
125117
- name: Create feature branch for PR
126-
if: env.create_release_feature_branch == 'true'
127118
run: |
128119
git switch -c feature/update-user-manual-for-$RELEASE_VERSION
129120
git push --set-upstream origin feature/update-user-manual-for-$RELEASE_VERSION
130121
131-
- name: Get feature branch for PR
132-
if: env.create_release_feature_branch == 'false'
133-
run: |
134-
git fetch origin feature/update-user-manual-for-$RELEASE_VERSION
135-
git switch feature/update-user-manual-for-$RELEASE_VERSION
136-
git pull
137-
138-
- name: Update user manual version
139-
run: |
140122
find docs -name 'user_manual.md' | xargs sed -i "s/code-scanning-cpp-query-pack-.*\.zip\`/code-scanning-cpp-query-pack-$RELEASE_VERSION.zip\`/"
141123
find docs -name 'user_manual.md' | xargs sed -i "s/supported_rules_list_.*\.csv\`/supported_rules_list_$RELEASE_VERSION.csv\`/"
142124
find docs -name 'user_manual.md' | xargs sed -i "s/supported_rules_list_.*\.md\`/supported_rules_list_$RELEASE_VERSION.md\`/"
143125
find docs -name 'user_manual.md' | xargs sed -i "s/user_manual_.*\.md\`/user_manual_$RELEASE_VERSION.md\`/"
144126
find docs -name 'user_manual.md' | xargs sed -i "s/This user manual documents release \`.*\` of/This user manual documents release \`$RELEASE_VERSION\` of/"
145127
146-
if ! git diff --quiet; then
147-
git add -u .
148-
git commit -m "Update version"
149-
git push
150-
fi
128+
git add -u .
129+
git commit -m "Update version"
130+
git push
151131
152132
- name: Create release PR
153133
env:
154134
GITHUB_TOKEN: ${{ secrets.ACTION_DISPATCH_TOKEN }}
155-
if: env.create_release_pr == 'true'
156135
run: |
157136
gh pr create \
158137
-R $GITHUB_REPOSITORY \

0 commit comments

Comments
 (0)