I'm saving a JSON field, .body
, to an ENV variable. The content of this field will always be changing with multiple strings and characters, it's the body message of a Pull Request in GitHub. So markdown will also get passed:
Below would be an accurate example extracted from .body
#Title
SubTitle
date
- Item 1
- Item 2
- Item 3
When I parse the JSON using jq and -r for its raw content:
echo "PR_BODY=$(jq -r '.body' $HOME/pr.json)" >> $GITHUB_ENV
I get errors from GitHub actions:
For reference, my plan is to save .body
data into a markdown file like so after managing to save it to an env variable:
run: |
ed changelog.md <<'END_ED'
1i
${{ env.PR_BODY }}
.
wq
END_ED
echo >> changelog.md
How can I go about extracting the data in .body
without empty spaces throwing errors? Perhaps an ENV variable is not the way to go about this?
EDIT: Here is an original raw JSON in the .body:
"body": "Manually configuring ports for DEV, CAT/QA environments. Migrating from managed service to self-serve \"GCP resource\". \r\n\r\n- [x] DEV\r\n- [x] CAT/QA\r\n- [ ] PROD\r\n\r\n```\r\n# Allow healthcheck on ports 80, 443\r\nresource \"google_compute_firewall\" \"allow-healthcheck\" {\r\n name = \"${format(\"%s\",\"${var.gcp_resource_name}-${var.gcp_env}-fw-allow-healthcheck\")}\"\r\n network = \"${google_compute_network.vpc.name}\"\r\n allow {\r\n protocol = \"tcp\"\r\n ports = [\"80\",\"443\"]\r\n }\r\n source_ranges = [\"2.2.0.0/16\", \"1.1.0.0/22\"]\r\n}\r\n```\r\nConfiguring for bug, link here:\r\n[Link To Terraform provider update](https://www.terraform.io/)"
.body
– yung peso Jun 16 '22 at 18:29$GITHUB_ENV
a shell script, or something else?echo "PR_BODY=$(jq -r '.body' $HOME/pr.json)" >> $GITHUB_ENV
will run the command substitution right then and there, so if the output ofjq
has multiple lines, they'll go into multiple lines in the output. That might break the expected syntax at the other end. – ilkkachu Jun 16 '22 at 18:33$GITHUB_ENV
is an environment file path native to Github actions. This is where someone can save env variables they they might use later down the road for another job. The expected syntax at the other is a simple mark down file. I demonstrated above how I would pass it to the markdown file. – yung peso Jun 16 '22 at 18:38/etc/environment
is on Linuxes)? If you want to shove a multi-line string in there, the first thing to do would be to find out what syntax it supports. – ilkkachu Jun 16 '22 at 18:43