Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1aa3b944 authored by Philipp Kewisch's avatar Philipp Kewisch
Browse files

Add missing push in uplift merges GH action

parent 724edf00
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -18,11 +18,22 @@ jobs:
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          sparse-checkout: |
            scripts/uplift-merges.sh
          sparse-checkout-cone-mode: false

      - name: Configure for push
        if: ${{ !inputs.dryRun }}
        run: |
          git config --global user.name "GitHub Actions Bot"
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

      - name: Run uplift script
        env:
          GH_TOKEN: ${{ github.token }}
          DRYRUN: ${{ inputs.dryRun && '' || '--no-dry-run' }}
          DRYRUN: ${{ !inputs.dryRun && '--no-dry-run' || '' }}
          BRANCH: ${{ github.ref_name }}
          PUSH: ${{ !inputs.dryRun && '--push' || '' }}
        run: |
          bash scripts/uplift-merges.sh $DRYRUN --$BRANCH
          bash scripts/uplift-merges.sh $DRYRUN --$BRANCH $PUSH | tee $GITHUB_STEP_SUMMARY
+33 −31
Original line number Diff line number Diff line
#!/bin/bash

# Check if gh is installed
if ! command -v gh &> /dev/null; then
    echo "Error: gh (GitHub CLI) is not installed."
function fail() {
  echo "Error: $*"
  exit 1
fi

# Check if jq is installed
if ! command -v jq &> /dev/null; then
    echo "Error: jq is not installed."
    exit 1
fi
}

# Check if git is installed
if ! command -v git &> /dev/null; then
    echo "Error: git is not installed."
    exit 1
fi
# Check if tools are installed
command -v gh &> /dev/null || fail "gh (GitHub CLI) is not installed"
command -v jq &> /dev/null || fail "jq is not installed"
command -v git &> /dev/null || fail "git is not installed"

# Default values
dry_run=true
repo=${GITHUB_REPOSITORY:-thunderbird/thunderbird-android}
label="task: uplift to beta"
branch="beta"
push=false

# Parse command-line arguments
for arg in "$@"; do
@@ -41,9 +34,12 @@ for arg in "$@"; do
      branch="beta"
      shift
      ;;
    --push)
      push=true
      shift
      ;;
    *)
      echo "Unknown argument: $arg"
      exit 1
      fail "Unknown argument: $arg"
      ;;
  esac
done
@@ -51,16 +47,19 @@ done
# Check if on the correct branch
current_branch=$(git branch --show-current)
if [ "$current_branch" != "$branch" ]; then
    echo "Error: You are not on the $branch branch. Please switch to the $branch branch."
    exit 1
    fail "You are not on the $branch branch. Please switch to the $branch branch."
fi

if [ "$dry_run" = true ]
then
  echo "Dry run in progress, to disable pass --no-dry-run"
fi

echo "Dry run: $dry_run, to disable dry run pass --no-dry-run"
echo "Label: \"$label\""
echo ""

# Fetch the uplift commits from the GitHub repository
json_data=$(gh pr list --repo "$repo" --label "$label" --state closed --json "mergedAt,mergeCommit,number,url")
json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --json "mergedAt,mergeCommit,number,url,title" | jq -c .)

# Sort by mergedAt
sorted_commits=$(echo "$json_data" | jq -c '. | sort_by(.mergedAt) | .[]')
@@ -72,22 +71,25 @@ if [ -z "$sorted_commits" ]; then
fi

# Generate git cherry-pick commands
for commit in $sorted_commits; do
while IFS= read -r commit
do
    oid=$(echo "$commit" | jq -r '.mergeCommit.oid')
    pr_number=$(echo "$commit" | jq -r '.number')
    pr_url=$(echo "$commit" | jq -r '.url')
    echo "Cherry-picking $oid from $pr_url"
    pr_title=$(echo "$commit" | jq -r '.title')
    echo "Cherry-picking $oid from $pr_url ($pr_title)"

    if [ "$dry_run" = false ]; then
        if git cherry-pick -m 1 "$oid"; then
          gh pr edit "$pr_number" --remove-label "$label"
        else
          echo "Failed to cherry-pick $oid"
          exit 1
        git cherry-pick -m 1 "$oid" || fail "Failed to cherry-pick $oid"
        if [ "$push" = true ]; then
          git push || fail "Failed to push $oid"
        fi

        gh pr edit "$pr_number" --repo "$repo" --remove-label "$label" || fail "Failed to remove label from $pr_number"
    else
        echo "git cherry-pick -m 1 $oid"
        echo "gh pr edit $pr_number --remove-label \"$label\""
        [ "$push" = true ] && echo git push
        echo "gh pr edit $pr_number --repo \"$repo\" --remove-label \"$label\""
    fi
    echo ""
done
done <<< "$sorted_commits"