nilsreichardt / codemagic-app-preview

Simplify your pull request reviews by automatically generating QR codes linked to your app builds for Android, iOS and macOS.
BSD 3-Clause "New" or "Revised" License
29 stars 3 forks source link

FIx manual launch workflow with codemagic ui #102

Open kcrebound opened 10 months ago

kcrebound commented 10 months ago

Got problem when trying to manual retry the workflow after having some issue in previous build

image

Prepared hack for it to update env variable based on found open pull request in github using gh

# Parse variables from env
REPO_OWNER=$(echo $CM_REPO_SLUG | cut -d'/' -f1)
REPO_NAME=$(echo $CM_REPO_SLUG | cut -d'/' -f2)
BRANCH_NAME="$CM_BRANCH"

# Auth to github using PAT
echo $GITHUB_PAT | gh auth login --with-token

# Use GitHub CLI to get the list of pull requests for the specified branch
# The '--jq' flag is used to parse the JSON response directly within the GitHub CLI
PR_ID=$(gh pr list --repo $REPO_OWNER/$REPO_NAME --head "$BRANCH_NAME" --state open --json number --jq '.[0].number')

if [ "$PR_ID" != "null" ]; then
  echo "Pull Request ID for branch '$BRANCH_NAME' is $PR_ID"
  # Set the pull request ID as an environment variable
  echo "CM_PULL_REQUEST_NUMBER=$PR_ID" >> $CM_ENV
else
  echo "No open pull request found for branch '$BRANCH_NAME'"
  exit 0
fi

With using it we solving problem with not idempotent behavior image

kcrebound commented 10 months ago

@nilsreichardt not an issue really, but decided to share it here, can be helpful for organizing smoothless dev experience

ps, thanks for package, it is awesome

nilsreichardt commented 10 months ago

Nice, thanks for the tip! This is something I could integrate into the CLI itself. As it is today, I can check if CM_PULL_REQUEST_NUMBER is empty and if yes, also check with gh CLI and only if this also empty then throw an exception that no pull request could be found.