Skip to content

Commit

Permalink
fix: Reversed version override flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kschrief committed Mar 25, 2024
1 parent f0d5a90 commit 3522598
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 54 deletions.
38 changes: 1 addition & 37 deletions .github/workflows/merge-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@ jobs:
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"
# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "main"
- name: Checkout main
run: git checkout "main"

# Update "main" version to match "next"
- name: Update "main" version to match "next"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json
if diff -q "package.json" "temp.json" >/dev/null; then
echo "Versions are identical. No change required."
rm temp.json
else
mv temp.json package.json
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi
# Attempt a dry-run merge
- name: Attempt a dry-run merge
run: |
Expand Down Expand Up @@ -70,28 +52,10 @@ jobs:
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"
# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "main"
- name: Checkout main
run: git checkout "main"

# Update "main" version to match "next"
- name: Update "main" version to match "next"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json
if diff -q "package.json" "temp.json" >/dev/null; then
echo "Versions are identical. No change required."
rm temp.json
else
mv temp.json package.json
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi
- name: Perform the merge from next to main
run: |
git merge origin/next
Expand All @@ -107,7 +71,7 @@ jobs:
exit 1
fi
# If the merge cannot be performed, let stakeholders know
# If the merge cannot be performed, let stakeholders know
process_merge_on_failure:
name: Merge dry-run failure
needs: check_merge
Expand Down
50 changes: 33 additions & 17 deletions .github/workflows/merge-to-next-major.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
push:
branches:
- "next"
- 'next'

jobs:
# Check if next can merge into next-major
Expand All @@ -24,17 +24,21 @@ jobs:
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"
# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "next-major"
- name: Checkout next-major
run: git checkout "next-major"

# Update "next-major" version to match "next"
- name: Update "next-major" version to match "next"
# Get the "next-major" version number
- name: Extract next-major version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "next"
- name: Checkout next
run: git checkout "next"

# Update "next" version to match "next-major"
- name: Update "next" version to match "next-major"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json
Expand All @@ -46,10 +50,14 @@ jobs:
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi
# Checkout "next-major"
- name: Checkout next-major
run: git checkout "next-major"

# Attempt a dry-run merge
- name: Attempt a dry-run merge
run: |
git merge --no-commit --no-ff origin/${{github.ref_name}}
git merge --no-commit --no-ff ${{github.ref_name}}
exit $?
# Attempt to merge to next-major if our dry-run succeeded
Expand All @@ -73,17 +81,21 @@ jobs:
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"
# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "next-major"
- name: Checkout next-major
run: git checkout "next-major"

# Update "next-major" version to match "next"
- name: Update "next-major" version to match "next"
# Get the "next-major" version number
- name: Extract next-major version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "next"
- name: Checkout next
run: git checkout "next"

# Update "next" version to match "next-major"
- name: Update "next" version to match "next-major"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json
Expand All @@ -95,9 +107,13 @@ jobs:
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi
# Checkout "next-major"
- name: Checkout next-major
run: git checkout "next-major"

- name: Perform the merge from next to next-major
run: |
git merge origin/next
git merge next
merge_status=$?
git push origin "next-major"
Expand Down

0 comments on commit 3522598

Please sign in to comment.