Skip to content

Commit

Permalink
Merge pull request #34 from CircleCI-Public/refactor/orb-tools-12-mig…
Browse files Browse the repository at this point in the history
…ration

refactor!: orb tools 12 migration
  • Loading branch information
brivu authored Sep 13, 2023
2 parents 4a9b896 + aed2f22 commit 9a395d7
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 249 deletions.
155 changes: 21 additions & 134 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,141 +1,28 @@
version: 2.1

setup: true
orbs:
orb-tools: circleci/[email protected]
jq: circleci/jq@<<pipeline.parameters.dev-orb-version>>

executors:
docker-base:
docker:
- image: cimg/base:stable
macos:
macos:
xcode: 14.2.0
machine:
machine:
image: ubuntu-2004:202101-01
# Pipeline parameters
parameters:
# These pipeline parameters are required by the "trigger-integration-tests-workflow"
# job, by default.
run-integration-tests:
type: boolean
default: false
dev-orb-version:
type: string
default: "dev:alpha"

jobs:
install:
parameters:
executor:
type: executor
version:
type: string
default: latest

executor: <<parameters.executor>>
steps:
- jq/install:
version: <<parameters.version>>
orb-tools: circleci/[email protected]
shellcheck: circleci/[email protected]

orb_prep_jobs: &orb_prep_jobs
[
orb-tools/lint,
orb-tools/pack
]

prod-deploy_requires: &prod-deploy_requires
[
install-latest-alpine,
install-latest-machine,
install-latest-macos,
install-latest-docker,
install-latest-oracle,
install-older-alpine,
]
filters: &filters
tags:
only: /.*/

workflows:
lint_pack-validate_publish-dev:
unless: << pipeline.parameters.run-integration-tests >>
lint-pack:
jobs:
- orb-tools/lint

- orb-tools/pack

- orb-tools/publish-dev:
context: orb-publisher
orb-name: circleci/jq
requires: *orb_prep_jobs

- orb-tools/trigger-integration-tests-workflow:
context: orb-publisher
requires: [orb-tools/publish-dev]

integration_tests-prod_deploy:
when: << pipeline.parameters.run-integration-tests >>
jobs:
# latest
- install:
name: install-latest-alpine
executor: orb-tools/alpine
context: orb-publisher
# Test that files are not left behind
post-steps:
- checkout

- install:
name: install-latest-machine
executor: machine
context: orb-publisher
# Test that files are not left behind
post-steps:
- checkout

- install:
name: install-latest-macos
executor: macos
context: orb-publisher
# Test that files are not left behind
post-steps:
- checkout

- install:
name: install-latest-docker
executor: docker-base
context: orb-publisher
# Test that files are not left behind
post-steps:
- checkout

- install:
name: install-latest-oracle
executor: orb-tools/oracle
context: orb-publisher
# Test that files are not left behind
post-steps:
- checkout

# older jq
- install:
name: install-older-alpine
executor: orb-tools/alpine
version: jq-1.5
context: orb-publisher
# Test that files are not left behind
post-steps:
- checkout
- orb-tools/lint:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/review:
filters: *filters
- shellcheck/check:
filters: *filters
- orb-tools/continue:
orb_name: jq
pipeline_number: << pipeline.number >>
vcs_type: << pipeline.project.type >>
requires: [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check]
filters: *filters

- orb-tools/dev-promote-prod-from-commit-subject:
ssh-fingerprints: 0c:0f:b7:32:1f:7e:55:1b:f9:e9:ba:93:f9:4f:e1:e3
context: orb-publisher
orb-name: circleci/jq
add-pr-comment: true
bot-token-variable: GHI_TOKEN
bot-user: orb-publisher
fail-if-semver-not-indicated: true
publish-version-tag: true
requires: *prod-deploy_requires
filters:
branches:
only: master
80 changes: 80 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: 2.1
orbs:
orb-tools: circleci/[email protected]
jq: {}
filters: &filters
tags:
only: /.*/
release-filters: &release-filters
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
executors:
docker-base:
docker:
- image: cimg/base:stable
alpine:
docker:
- image: alpine:latest
macos:
macos:
xcode: 14.2.0
machine:
machine:
image: ubuntu-2004:202101-01

jobs:
install:
parameters:
executor:
type: executor
version:
type: string
default: latest
executor: <<parameters.executor>>
steps:
- jq/install:
version: <<parameters.version>>

workflows:
integration_tests-prod_deploy:
jobs:
# latest
- install:
name: install-latest-alpine
executor: alpine
context: orb-publisher

- install:
name: install-latest-machine
executor: machine
context: orb-publisher

- install:
name: install-latest-macos
executor: macos
context: orb-publisher

- install:
name: install-latest-docker
executor: docker-base
context: orb-publisher

# older jq
- install:
name: install-older-alpine
executor: alpine
version: jq-1.5
context: orb-publisher

- orb-tools/pack:
filters: *release-filters
- orb-tools/publish:
orb_name: circleci/jq
vcs_type: << pipeline.project.type >>
pub_type: production
enable_pr_comment: true
requires: [orb-tools/pack, ]
context: orb-publisher
filters: *release-filters
117 changes: 6 additions & 111 deletions src/commands/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parameters:
version other than latest, provide a full release tag, as listed at
https://api.github.com/repos/jqlang/jq/releases, e.g., `jq-1.6`.
install-dir:
install_dir:
type: string
default: ~/bin
description: >
Expand All @@ -24,116 +24,11 @@ parameters:
Whether or not to remove a pre-existing version of jq when this version
is installed.
when:
type: enum
default: "always"
description: When to run the command.
enum: ["always", "on_fail", "on_success"]

steps:
- run:
when: << parameters.when >>
name: Install jq
command: |
# Quietly try to make the install directory.
mkdir -p << parameters.install-dir >> | true
# Selectively export the SUDO command, depending if we have permission
# for a directory and whether we're running alpine.
if [[ $EUID == 0 ]]; then export SUDO=""; else # Check if we're root
if cat /etc/issue | grep Alpine > /dev/null 2>&1 || ! [[ -w "<< parameters.install-dir >>" ]]; then
export SUDO="sudo";
fi
fi
# If our first mkdir didn't succeed, we needed to run as sudo.
if [ ! -w << parameters.install-dir >> ]; then
$SUDO mkdir -p << parameters.install-dir >>
fi
echo 'export PATH=$PATH:<< parameters.install-dir >>' >> $BASH_ENV
source $BASH_ENV
# check if jq needs to be installed
if command -v jq >> /dev/null 2>&1; then
echo "jq is already installed..."
if [[ <<parameters.override>> == true ]]; then
echo "removing it."
$SUDO rm -f $(command -v jq)
else
echo "ignoring install request."
exit 0
fi
fi
# Set jq version
if [[ <<parameters.version>> == "latest" ]]; then
JQ_VERSION=$(curl -Ls -o /dev/null -w %{url_effective} "https://github.com/jqlang/jq/releases/latest" | sed 's:.*/::')
echo "Latest version of jq is $JQ_VERSION"
else
JQ_VERSION=<<parameters.version>>
fi
# extract version number
JQ_VERSION_NUMBER_STRING=$(echo $JQ_VERSION | sed -E 's/-/ /')
arrJQ_VERSION_NUMBER=($JQ_VERSION_NUMBER_STRING)
JQ_VERSION_NUMBER="${arrJQ_VERSION_NUMBER[1]}"
# Set binary download URL for specified version
# handle mac version
if uname -a | grep Darwin > /dev/null 2>&1; then
JQ_BINARY_URL="https://github.com/jqlang/jq/releases/download/${JQ_VERSION}/jq-osx-amd64"
else
# linux version
JQ_BINARY_URL="https://github.com/jqlang/jq/releases/download/${JQ_VERSION}/jq-linux64"
fi
jqBinary="jq-$PLATFORM"
if [ -d "$JQ_VERSION/sig" ]; then
# import jq sigs
if uname -a | grep Darwin > /dev/null 2>&1; then
HOMEBREW_NO_AUTO_UPDATE=1 brew install gnupg coreutils
PLATFORM=osx-amd64
else
if cat /etc/issue | grep Alpine > /dev/null 2>&1; then
$SUDO apk add gnupg > /dev/null 2>&1
fi
PLATFORM=linux64
fi
gpg --import "$JQ_VERSION/sig/jq-release.key" > /dev/null
curl --output "$JQ_VERSION/sig/v$JQ_VERSION_NUMBER/jq-$PLATFORM" \
--silent --show-error --location --fail --retry 3 \
"$JQ_BINARY_URL"
# verify sha256sum, sig, install
gpg --verify "$JQ_VERSION/sig/v$JQ_VERSION_NUMBER/jq-$PLATFORM.asc"
pushd "$JQ_VERSION/sig/v$JQ_VERSION_NUMBER" && grep "jq-$PLATFORM" "sha256sum.txt" | \
sha256sum -c -
popd
jqBinary="$JQ_VERSION/sig/v$JQ_VERSION_NUMBER/jq-$PLATFORM"
else
curl --output "$jqBinary" \
--silent --show-error --location --fail --retry 3 \
"$JQ_BINARY_URL"
fi
$SUDO mv "$jqBinary" <<parameters.install-dir>>/jq
$SUDO chmod +x <<parameters.install-dir>>/jq
# cleanup
[[ -d "./$JQ_VERSION" ]] && rm -rf "./$JQ_VERSION"
# verify version
echo "jq has been installed to $(which jq)"
echo "jq version:"
echo "$(jq --version)"
environment:
JQ_STR_VERSION: << parameters.version >>
JQ_EVAL_INSTALL_DIR: << parameters.install_dir >>
JQ_BOOL_OVERRIDE: << parameters.override >>
command: <<include(scripts/install.sh)>>
8 changes: 4 additions & 4 deletions src/examples/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ usage:
version: 2.1

orbs:
jq: circleci/jq@x.y.z
jq: circleci/jq@3.0.0

jobs:
build:
docker:
- image: your-image
- image: cimg/base:current
steps:
- checkout
- jq/install
- jq/install:
version: jq-1.7

workflows:
your-workflow:
Expand Down
Loading

0 comments on commit 9a395d7

Please sign in to comment.