Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/bin/bash: line 1: GITHUB_STATUS_CONTEXT: unbound variable #1

Open
falkenhawk opened this issue Nov 18, 2020 · 2 comments · May be fixed by #2
Open

/bin/bash: line 1: GITHUB_STATUS_CONTEXT: unbound variable #1

falkenhawk opened this issue Nov 18, 2020 · 2 comments · May be fixed by #2

Comments

@falkenhawk
Copy link

falkenhawk commented Nov 18, 2020

Hi,
I am trying to use your orb in my circleci config.
But it crashes right away at the "pending" command. What am I missing?

version: 2.1
orbs:
  github-status: samsalisbury/[email protected]
jobs:
  test:
    docker:
      - image: circleci/node:12
    steps:
      - github-status/pending
#!/bin/bash -eo pipefail
set -euo pipefail
CONTEXT="$GITHUB_STATUS_CONTEXT"
DESCRIPTION="$GITHUB_STATUS_DESCRIPTION"
[ -n "$CONTEXT" ] || CONTEXT="circleci/$CIRCLE_JOB"
[ -n "$DESCRIPTION" ] || DESCRIPTION="$CONTEXT"
# Export the latest values for CONTEXT and DESCRIPTION so later calls
# do not need to set them explicitly again.
echo "export GITHUB_STATUS_CONTEXT='$CONTEXT'" >> $BASH_ENV
echo "export GITHUB_STATUS_DESCRIPTION='$DESCRIPTION'" >> $BASH_ENV
# Compose our URL and auth pieces.
API=https://api.github.com
USER=$CIRCLE_PROJECT_USERNAME
REPO=$CIRCLE_PROJECT_REPONAME
SHA=$CIRCLE_SHA1
AUTH=$GITHUB_STATUS_USER:$GITHUB_STATUS_TOKEN
URL=$API/repos/$USER/$REPO/statuses/$SHA
# Compose the body.
BODY='
  {
    "state": "pending",
    "target_url": "$CIRCLE_BUILD_URL",
    "description": "pending: '"$DESCRIPTION"'",
    "context": "'"$CONTEXT"'"
  }
'
# Post the status (use echo-pipe not <<< for greater shell compat).
echo $BODY | curl -u $AUTH -XPOST -d@- $URL

/bin/bash: line 1: GITHUB_STATUS_CONTEXT: unbound variable

Exited with code exit status 1

CircleCI received exit code 1
@falkenhawk
Copy link
Author

falkenhawk commented Nov 18, 2020

okay I see now. I compared my cci job with yours, which was successful https://app.circleci.com/pipelines/github/samsalisbury/orb-github-status/8/workflows/4dce4298-03fc-473f-aaa9-06f084f8ed31/jobs/17

this is missing: (among others)

set +u # Allow context and description to contain unbound variables.

and apparently you are still using 0.0.1 version in your circleci.yml config:
https://github.com/samsalisbury/orb-github-status/blob/master/.circleci/config.yml#L4

So FYI, 0.0.2 does not work (affecting commit: 98c3b3b), and 0.0.1 seems to work.

@falkenhawk
Copy link
Author

falkenhawk commented Nov 18, 2020

Unfortunately, 0.0.1 does not work on macos environment in turn. I haven't checked 0.0.2 on macos.

version: 2.1
orbs:
  github-status: samsalisbury/[email protected]
jobs:
  build-ios:
    macos:
      xcode: "11.1.0"
    steps:
      - github-status/pending

Result:

#!/bin/bash -eo pipefail
set -euo pipefail
set +u # Allow context and description to contain unbound variables.
CONTEXT="$GITHUB_STATUS_CONTEXT"
DESCRIPTION="$GITHUB_STATUS_DESCRIPTION"
set -u
[ -n "$CONTEXT" ] || CONTEXT="circleci/$CIRCLE_JOB"
[ -n "$DESCRIPTION" ] || DESCRIPTION="$CONTEXT"
# Export the latest values for CONTEXT and DESCRIPTION so later calls
# do not need to set them explicitly again.
echo "export GITHUB_STATUS_CONTEXT='$CONTEXT'" >> $BASH_ENV
echo "export GITHUB_STATUS_DESCRIPTION='$DESCRIPTION'" >> $BASH_ENV
# Compose our URL and auth pieces.
API=https://api.github.com
USER=$CIRCLE_PROJECT_USERNAME
REPO=$CIRCLE_PROJECT_REPONAME
SHA=$CIRCLE_SHA1
AUTH=$GITHUB_STATUS_USER:$GITHUB_STATUS_TOKEN
URL=$API/repos/$USER/$REPO/statuses/$SHA
# Compose the body.
# The read below will exit with 1 as it hits EOF,
# so we temporarily disable error checking.
set +e
read -r -d '' BODY <<EOF
  {
    "state": "pending",
    "target_url": "$CIRCLE_BUILD_URL",
    "description": "pending: $DESCRIPTION",
    "context": "$CONTEXT"
  } 
EOF
set -euo pipefail
# Post the status (use echo-pipe not <<< for greater shell compat).
echo $BODY | curl -u $AUTH -XPOST -d@- $URL

/bin/bash: line 1: PROMPT_COMMAND: unbound variable

I've found this regarding that PROMPT_COMMAND - might be related: pytorch/pytorch@588a838

falkenhawk added a commit to ovos/orb-github-status that referenced this issue Nov 19, 2020
This fixes execution issues mentioned in samsalisbury#1 for both linux and macos runners
fixes samsalisbury#1
@falkenhawk falkenhawk linked a pull request Nov 19, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant