Skip to content

Commit

Permalink
Make sure to sync to upstream before changes
Browse files Browse the repository at this point in the history
Since the merged commit will have a different hash, we need to make sure
to sync up the local branch before doing any additional changes.

Signed-off-by: Mike Kolesnik <[email protected]>
  • Loading branch information
mkolesnik committed Dec 9, 2021
1 parent 916e5b7 commit e8e8248
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions scripts/lib/utils
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ function clone_repo() {
}

function checkout_project_branch() {
local base_branch="origin/${release['branch']:-devel}"
local branch="${release["components.${project}"]:-${base_branch}}"
local default_branch="origin/${release['branch']:-devel}"
local branch="${release["components.${project}"]:-${default_branch}}"

_git reset --hard HEAD
_git checkout "${branch}"
Expand Down
14 changes: 11 additions & 3 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ function set_status() {
sed -i -E "s/(status: ).*/\1${1}/" "${file}"
}

function sync_upstream() {
local gh_user="${GITHUB_ACTOR:-${ORG}}"
git remote rm upstream_releases 2> /dev/null || :
git remote add upstream_releases "https://github.com/${gh_user}/releases.git"
git fetch upstream_releases "${BASE_BRANCH}"
git rebase "upstream_releases/${BASE_BRANCH}"
}

### Functions: Creating initial release ###

function create_pr() {
local branch="$1"
local msg="$2"
# shellcheck disable=SC2153
local base_branch="${BASE_BRANCH}"
local pr_to_review
local project

Expand All @@ -62,7 +68,7 @@ function create_pr() {
git add "${file}"
git commit -s -m "${msg}"
dryrun git push -f "https://${GITHUB_TOKEN}:[email protected]/${gh_user}/${project}.git" "HEAD:${branch}"
pr_to_review=$(dryrun gh pr create --repo "${repo}" --head "${gh_user}:${branch}" --base "${base_branch}" --title "${msg}" --body "${msg}")
pr_to_review=$(dryrun gh pr create --repo "${repo}" --head "${gh_user}:${branch}" --base "${BASE_BRANCH}" --title "${msg}" --body "${msg}")
dryrun gh pr merge --auto --repo "${repo}" --rebase "${pr_to_review}" \
|| echo "WARN: Failed to enable auto merge on ${pr_to_review}"
echo "Created Pull Request: ${pr_to_review}"
Expand All @@ -71,6 +77,7 @@ function create_pr() {

function create_initial() {
declare -gA release
sync_upstream
echo "Creating initial release file ${file}"
cat > "${file}" <<EOF
---
Expand Down Expand Up @@ -135,6 +142,7 @@ function advance_stage() {
read_release_file
case "${release['status']}" in
branch|shipyard|admiral|projects)
sync_upstream
local next="${NEXT_STATUS[${release['status']}]}"
set_status "${next}"
# shellcheck disable=SC2086
Expand Down
5 changes: 4 additions & 1 deletion scripts/test/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ function test_release() {
done

# Since the branch is expected to exist, the script will fail, so remove it for testing
[[ "${status}" == 'branch' ]] && sed -i '/^branch:.*/d' "releases/v${version}.yaml"
if [[ "${status}" == 'branch' ]]; then
sed -i '/^branch:.*/d' "releases/v${version}.yaml"
git commit -a -m "Remove branch or make release will fail" > /dev/null
fi

while [[ -n "${NEXT_STATUS[${status}]}" ]]; do
status="${NEXT_STATUS[${status}]}"
Expand Down

0 comments on commit e8e8248

Please sign in to comment.