From a60e5e7cb869f86db10d14511698beef3ea74fb8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 11 Oct 2024 14:07:48 -0400 Subject: [PATCH] add vars to workflow --- .github/workflows/scripts/bump-versions.sh | 32 ++++++++-------- .github/workflows/update-version.yaml | 43 +++++++++++++++------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/.github/workflows/scripts/bump-versions.sh b/.github/workflows/scripts/bump-versions.sh index e814abae..f622b1e4 100755 --- a/.github/workflows/scripts/bump-versions.sh +++ b/.github/workflows/scripts/bump-versions.sh @@ -8,7 +8,7 @@ # Function to display usage usage() { - echo "Usage: $0 [--commit] [--push] --current-beta-core [--current-beta-contrib ] [--current-stable ] [--next-beta-core ] [--next-beta-contrib ] [--next-stable ]" + echo "Usage: $0 [--commit] [--pull-request] --current-beta-core [--current-beta-contrib ] [--current-stable ] [--next-beta-core ] [--next-beta-contrib ] [--next-stable ]" echo " --current-beta-core: Current beta version of the core component (e.g., v0.110.0)" echo " --current-beta-contrib: Current beta version of the contrib component (e.g., v0.110.0)" echo " --current-stable: Current stable version of the core component (e.g., v1.16.0)" @@ -19,7 +19,7 @@ usage() { echo " --next-stable: Next stable version of the core component (e.g., v1.17.0)" echo echo " --commit: Commit the changes to a new branch" - echo " --push: Push the changes to the repo and create a draft PR (requires --commit)" + echo " --pull-request: Push the changes to the repo and create a draft PR (requires --commit)" exit 1 } @@ -36,7 +36,7 @@ validate_and_strip_version() { eval "$var_name='$version'" } commit_changes=false -push_changes=false +create_pr=false # Parse named arguments while [[ "$#" -gt 0 ]]; do case $1 in @@ -47,15 +47,15 @@ while [[ "$#" -gt 0 ]]; do --next-beta-contrib) next_beta_contrib="$2"; shift ;; --next-stable) next_stable="$2"; shift ;; --commit) commit_changes=true ;; - --push) push_changes=true ;; + --pull-request) create_pr=true ;; *) echo "Unknown parameter passed: $1"; usage ;; esac shift done -# Check if --push is passed without --commit -if [ "$push_changes" = true ] && [ "$commit_changes" = false ]; then - echo "--push requires --commit" +# Check if --pull-request is passed without --commit +if [ "$create_pr" = true ] && [ "$commit_changes" = false ]; then + echo "--pull-request requires --commit" usage fi @@ -149,7 +149,7 @@ done echo "Version update completed." # Commit changes and draft PR -if [ "$commit_changes" = false ] && [ "$push_changes" = false ]; then +if [ "$commit_changes" = false ] && [ "$create_pr" = false ]; then echo "Changes not committed and PR not created." exit 0 fi @@ -168,15 +168,15 @@ commit_changes() { git add "$file" done git commit -m "Update version from $current_version to $next_version" + git push -u origin "$branch_name" } -push_changes_and_create_pr() { +create_pr() { local current_version=$1 local next_version=$2 shift 2 local branch_name="update-version-${next_version}" - git push -u origin "$branch_name" gh pr create --title "[chore] Prepare release $next_version" \ --body "This PR updates the version from $current_version to $next_version" \ --base main --head "$branch_name" --draft @@ -188,22 +188,22 @@ if [ -n "$current_beta_core" ]; then if [ "$commit_changes" = true ]; then commit_changes "$current_beta_core" "$next_beta_core" fi - if [ "$push_changes" = true ]; then - push_changes_and_create_pr "$current_beta_core" "$next_beta_core" + if [ "$create_pr" = true ]; then + create_pr "$current_beta_core" "$next_beta_core" fi elif [ -n "$current_beta_contrib" ]; then if [ "$commit_changes" = true ]; then commit_changes "$current_beta_contrib" "$next_beta_contrib" fi - if [ "$push_changes" = true ]; then - push_changes_and_create_pr "$current_beta_contrib" "$next_beta_contrib" + if [ "$create_pr" = true ]; then + create_pr "$current_beta_contrib" "$next_beta_contrib" fi else if [ "$commit_changes" = true ]; then commit_changes "$current_stable" "$next_stable" fi - if [ "$push_changes" = true ]; then - push_changes_and_create_pr "$current_stable" "$next_stable" + if [ "$create_pr" = true ]; then + create_pr "$current_stable" "$next_stable" fi fi diff --git a/.github/workflows/update-version.yaml b/.github/workflows/update-version.yaml index cbe61f6a..7b7a8e11 100644 --- a/.github/workflows/update-version.yaml +++ b/.github/workflows/update-version.yaml @@ -2,22 +2,35 @@ name: Update Version on: workflow_dispatch: inputs: - current_beta: - description: 'Current beta version, e.g. v0.111.0 or 0.111.0' + current_beta_core: + description: 'Current collector core beta version, e.g. v0.111.0 or 0.111.0' + required: false + default: '' + current_beta_contrib: + description: 'Current collector contrib beta version, e.g. v0.111.0 or 0.111.0' required: false default: '' current_stable: description: 'Current stable version, e.g. v1.16.0 or 1.16.0' required: false default: '' - next_beta: - description: 'Next beta version (optional)' + next_beta_core: + description: 'Next collector core beta version (optional)' + required: false + default: '' + next_beta_contrib: + description: 'Next collector contrib beta version (optional)' required: false default: '' next_stable: description: 'Next stable version (optional)' required: false default: '' + create_pr: + description: 'Push changes to a new branch and create a draft pull request' + required: true + type: boolean + default: true jobs: update-version: @@ -27,8 +40,8 @@ jobs: steps: - name: Validate inputs run: | - if [ -z "${{ github.event.inputs.current_beta }}" ] && [ -z "${{ github.event.inputs.current_stable }}" ]; then - echo "Error: At least one of 'current_beta' or 'current_stable' must be provided." + if [ -z "${{ github.event.inputs.current_beta_core }}" ] && [ -z "${{ github.event.inputs.current_beta_contrib }}" ] && [ -z "${{ github.event.inputs.current_stable }}" ]; then + echo "Error: At least one of 'current_beta_core', 'current_beta_contrib', or 'current_stable' must be provided." exit 1 fi @@ -37,11 +50,15 @@ jobs: - name: Run bump-versions.sh run: | - chmod +x .github/workflows/scripts/bump-versions.sh - .github/workflows/scripts/bump-versions.sh \ - --current_beta "${{ github.event.inputs.current_beta }}" \ - --current_stable "${{ github.event.inputs.current_stable }}" \ - --next_beta "${{ github.event.inputs.next_beta }}" \ - --next_stable "${{ github.event.inputs.next_stable }}" + args="" + if [ "${{ github.event.inputs.create_pr }}" = "true" ]; then + args="--commit --pull-request" + fi + ./bump-versions.sh $args env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + current_beta_core: ${{ github.event.inputs.current_beta_core }} + current_beta_contrib: ${{ github.event.inputs.current_beta_contrib }} + current_stable: ${{ github.event.inputs.current_stable }} + next_beta_core: ${{ github.event.inputs.next_beta_core }} + next_beta_contrib: ${{ github.event.inputs.next_beta_contrib }} + next_stable: ${{ github.event.inputs.next_stable }}