mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-08 06:45:38 +00:00
Compare commits
13 Commits
cbae03d4a1
...
0416ce33e2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0416ce33e2 | ||
|
|
c5cbf9760b | ||
|
|
b5cb9a2f20 | ||
|
|
133ba767a6 | ||
|
|
5db3dcf394 | ||
|
|
4c148178e2 | ||
|
|
4df6e46f95 | ||
|
|
6a965bc39a | ||
|
|
34d3a29308 | ||
|
|
9ce5c8afee | ||
|
|
f20f287d5b | ||
|
|
c8efd595fc | ||
|
|
fc8a3fc3ce |
2
.github/workflows/docker-release.yml
vendored
2
.github/workflows/docker-release.yml
vendored
@ -23,7 +23,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.26.0 AS builder
|
FROM golang:1.26.1 AS builder
|
||||||
|
|
||||||
WORKDIR /go/src/mikefarah/yq
|
WORKDIR /go/src/mikefarah/yq
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.26.0
|
FROM golang:1.26.1
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y npm && \
|
apt-get install -y npm && \
|
||||||
|
|||||||
@ -478,3 +478,4 @@ yq ".a.b[0].c = \"value\"" file.yaml
|
|||||||
- "yes", "no" were dropped as boolean values in the yaml 1.2 standard - which is the standard yq assumes.
|
- "yes", "no" were dropped as boolean values in the yaml 1.2 standard - which is the standard yq assumes.
|
||||||
|
|
||||||
See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions.
|
See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions.
|
||||||
|
|
||||||
|
|||||||
104
action.yml
104
action.yml
@ -1,17 +1,105 @@
|
|||||||
name: 'yq - portable yaml processor'
|
name: "yq - portable yaml processor"
|
||||||
description: 'create, read, update, delete, merge, validate and do more with yaml'
|
description: "create, read, update, delete, merge, validate and do more with yaml"
|
||||||
branding:
|
branding:
|
||||||
icon: command
|
icon: command
|
||||||
color: gray-dark
|
color: gray-dark
|
||||||
inputs:
|
inputs:
|
||||||
|
image:
|
||||||
|
description: 'Container image to run. Example: "mikefarah/yq:4-githubaction" or fully qualified "artifacts.example.com/repo/mikefarah/yq:4-githubaction".'
|
||||||
|
required: false
|
||||||
|
default: "mikefarah/yq:4-githubaction"
|
||||||
|
registry:
|
||||||
|
description: "Optional artifact repository hostname to prefix the `image`. Leave empty if your `image` already includes a registry."
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
registry_username:
|
||||||
|
description: "Optional registry username for `docker login` (use with `registry_password`)."
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
registry_password:
|
||||||
|
description: "Optional registry password for `docker login` (use with `registry_username`). Pass secrets via workflow `with:` from secrets."
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
cmd:
|
cmd:
|
||||||
description: 'The Command which should be run'
|
description: "The Command which should be run"
|
||||||
required: true
|
required: true
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- id: pull-with-credentials
|
||||||
|
name: Pull image using provided credentials
|
||||||
|
if: ${{ inputs.registry_username && inputs.registry_password && inputs.registry }}
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
IMAGE_INPUT: ${{ inputs.image }}
|
||||||
|
REGISTRY: ${{ inputs.registry }}
|
||||||
|
REG_USER: ${{ inputs.registry_username }}
|
||||||
|
REG_PASS: ${{ inputs.registry_password }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
IMAGE="$IMAGE_INPUT"
|
||||||
|
if [ -n "$REGISTRY" ]; then
|
||||||
|
REG="${REGISTRY%/}"
|
||||||
|
IMAGE="$REG/$IMAGE"
|
||||||
|
fi
|
||||||
|
echo "Using image: $IMAGE"
|
||||||
|
echo "Credentials provided; attempting docker login to $REGISTRY"
|
||||||
|
if [ -n "$REG_PASS" ]; then
|
||||||
|
echo "::add-mask::$REG_PASS"
|
||||||
|
fi
|
||||||
|
echo "$REG_PASS" | docker login "$REGISTRY" --username "$REG_USER" --password-stdin
|
||||||
|
if docker pull "$IMAGE" >/dev/null 2>&1; then
|
||||||
|
echo "Image pulled successfully after login."
|
||||||
|
else
|
||||||
|
echo "Failed to pull image after login; proceeding to run (docker run may fail)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- id: pull-anonymous
|
||||||
|
name: Pull image anonymously
|
||||||
|
if: ${{ !(inputs.registry_username && inputs.registry_password && inputs.registry) }}
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
IMAGE_INPUT: ${{ inputs.image }}
|
||||||
|
REGISTRY: ${{ inputs.registry }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
IMAGE="$IMAGE_INPUT"
|
||||||
|
if [ -n "$REGISTRY" ]; then
|
||||||
|
REG="${REGISTRY%/}"
|
||||||
|
IMAGE="$REG/$IMAGE"
|
||||||
|
fi
|
||||||
|
echo "Using image: $IMAGE"
|
||||||
|
echo "No credentials provided (or registry not set); attempting anonymous pull"
|
||||||
|
if docker pull "$IMAGE" >/dev/null 2>&1; then
|
||||||
|
echo "Anonymous pull succeeded."
|
||||||
|
else
|
||||||
|
echo "Anonymous pull failed; proceeding to run (docker run may fail if auth required)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- id: run
|
||||||
|
name: Run yq container
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
IMAGE_INPUT: ${{ inputs.image }}
|
||||||
|
REGISTRY: ${{ inputs.registry }}
|
||||||
|
CMD_INPUT: ${{ inputs.cmd }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
IMAGE="$IMAGE_INPUT"
|
||||||
|
if [ -n "$REGISTRY" ]; then
|
||||||
|
REG="${REGISTRY%/}"
|
||||||
|
IMAGE="$REG/$IMAGE"
|
||||||
|
fi
|
||||||
|
echo "Using image: $IMAGE"
|
||||||
|
RC=0
|
||||||
|
OUTPUT=$(docker run --rm -v "$GITHUB_WORKSPACE":/work -w /work "$IMAGE" sh -lc "$CMD_INPUT" 2>&1) || RC=$?
|
||||||
|
echo "result<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo "$OUTPUT" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
if [ "$RC" -ne 0 ]; then
|
||||||
|
exit "$RC"
|
||||||
|
fi
|
||||||
outputs:
|
outputs:
|
||||||
result:
|
result:
|
||||||
description: "The complete result from the yq command being run"
|
description: "The complete result from the yq command being run"
|
||||||
runs:
|
value: ${{ steps.run.outputs.result }}
|
||||||
using: 'docker'
|
|
||||||
image: 'docker://mikefarah/yq:4-githubaction'
|
|
||||||
args:
|
|
||||||
- ${{ inputs.cmd }}
|
|
||||||
|
|||||||
@ -911,7 +911,7 @@ func stringsEqual(a, b []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i := range a {
|
for i := range a {
|
||||||
if a[i] != b[i] {
|
if a[i] != b[i] { //nolint:gosec // G602 false positive: b length equality is checked above
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
go.mod
18
go.mod
@ -18,11 +18,11 @@ require (
|
|||||||
github.com/spf13/cobra v1.10.2
|
github.com/spf13/cobra v1.10.2
|
||||||
github.com/spf13/pflag v1.0.10
|
github.com/spf13/pflag v1.0.10
|
||||||
github.com/yuin/gopher-lua v1.1.1
|
github.com/yuin/gopher-lua v1.1.1
|
||||||
github.com/zclconf/go-cty v1.17.0
|
github.com/zclconf/go-cty v1.18.0
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.3
|
go.yaml.in/yaml/v4 v4.0.0-rc.3
|
||||||
golang.org/x/mod v0.33.0
|
golang.org/x/mod v0.34.0
|
||||||
golang.org/x/net v0.50.0
|
golang.org/x/net v0.52.0
|
||||||
golang.org/x/text v0.34.0
|
golang.org/x/text v0.35.0
|
||||||
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
|
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,11 +34,9 @@ require (
|
|||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
golang.org/x/sync v0.19.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
golang.org/x/sys v0.41.0 // indirect
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
golang.org/x/tools v0.41.0 // indirect
|
golang.org/x/tools v0.42.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.24.0
|
go 1.25.0
|
||||||
|
|
||||||
toolchain go1.24.1
|
|
||||||
|
|||||||
28
go.sum
28
go.sum
@ -63,26 +63,26 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
|
|||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||||
github.com/zclconf/go-cty v1.17.0 h1:seZvECve6XX4tmnvRzWtJNHdscMtYEx5R7bnnVyd/d0=
|
github.com/zclconf/go-cty v1.18.0 h1:pJ8+HNI4gFoyRNqVE37wWbJWVw43BZczFo7KUoRczaA=
|
||||||
github.com/zclconf/go-cty v1.17.0/go.mod h1:wqFzcImaLTI6A5HfsRwB0nj5n0MRZFwmey8YoFPPs3U=
|
github.com/zclconf/go-cty v1.18.0/go.mod h1:qpnV6EDNgC1sns/AleL1fvatHw72j+S+nS+MJ+T2CSg=
|
||||||
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
|
||||||
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
|
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||||
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI=
|
||||||
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY=
|
||||||
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
|
||||||
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
|
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
|
||||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||||
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||||
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE=
|
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE=
|
||||||
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
|
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
|
||||||
|
|||||||
@ -280,7 +280,7 @@ func (n *CandidateNode) AddChild(rawChild *CandidateNode) {
|
|||||||
|
|
||||||
func (n *CandidateNode) AddChildren(children []*CandidateNode) {
|
func (n *CandidateNode) AddChildren(children []*CandidateNode) {
|
||||||
if n.Kind == MappingNode {
|
if n.Kind == MappingNode {
|
||||||
for i := 0; i < len(children); i += 2 {
|
for i := 0; i < len(children)-1; i += 2 {
|
||||||
key := children[i]
|
key := children[i]
|
||||||
value := children[i+1]
|
value := children[i+1]
|
||||||
n.AddKeyValueChild(key, value)
|
n.AddKeyValueChild(key, value)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ func GetLogger() *logging.Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getContentValueByKey(content []*CandidateNode, key string) *CandidateNode {
|
func getContentValueByKey(content []*CandidateNode, key string) *CandidateNode {
|
||||||
for index := 0; index < len(content); index = index + 2 {
|
for index := 0; index < len(content)-1; index = index + 2 {
|
||||||
keyNode := content[index]
|
keyNode := content[index]
|
||||||
valueNode := content[index+1]
|
valueNode := content[index+1]
|
||||||
if keyNode.Value == key {
|
if keyNode.Value == key {
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
set -o errexit
|
set -o errexit
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
# TODO: Check if the found golangci-lint version matches the expected version (e.g., v1.62.0), especially if falling back to PATH version.
|
|
||||||
|
|
||||||
GOPATH_LINT="$(go env GOPATH)/bin/golangci-lint"
|
GOPATH_LINT="$(go env GOPATH)/bin/golangci-lint"
|
||||||
BIN_LINT="./bin/golangci-lint"
|
BIN_LINT="./bin/golangci-lint"
|
||||||
LINT_CMD=""
|
LINT_CMD=""
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -ex
|
set -ex
|
||||||
go mod download golang.org/x/tools@latest
|
go mod download golang.org/x/tools@latest
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.5
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.11.3
|
||||||
curl -sSfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s v2.22.11
|
curl -sSfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s v2.22.11
|
||||||
Loading…
Reference in New Issue
Block a user