Skip to content

Commit 7eb4cc6

Browse files
authored
Make the first version of Install 1Password CLI GitHub Action (#1)
This GitHub Action installs the 1Password CLI in GitHub Action runners. It supports installing the latest stable version (default), latest beta, or a specific version. Current runners supported: Linux (most archs), macOS.
1 parent 464837d commit 7eb4cc6

File tree

6 files changed

+250
-2
lines changed

6 files changed

+250
-2
lines changed

.github/workflows/test.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
on: push
2+
name: Test installation
3+
4+
jobs:
5+
use-latest-version:
6+
name: "Test getting latest CLI stable version"
7+
strategy:
8+
matrix:
9+
os: [ubuntu-latest, macos-latest]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Install 1Password CLI
14+
uses: ./ # 1password/install-cli-action@<version>
15+
- name: Check CLI version
16+
run: ./test/assert-version.sh latest
17+
use-latest-beta-version:
18+
name: "Test getting latest CLI beta version"
19+
strategy:
20+
matrix:
21+
os: [ubuntu-latest, macos-latest]
22+
runs-on: ${{ matrix.os }}
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Install 1Password CLI
26+
uses: ./ # 1password/install-cli-action@<version>
27+
with:
28+
version: latest-beta
29+
- name: Check CLI version
30+
run: ./test/assert-version.sh latest-beta
31+
use-specific-version:
32+
name: "Test getting a specific CLI version"
33+
strategy:
34+
matrix:
35+
os: [ubuntu-latest, macos-latest]
36+
runs-on: ${{ matrix.os }}
37+
steps:
38+
- uses: actions/checkout@v3
39+
- name: Install 1Password CLI
40+
uses: ./ # 1password/install-cli-action@<version>
41+
with:
42+
version: 2.18.0
43+
- name: Check CLI version
44+
run: ./test/assert-version.sh 2.18.0
45+
use-specific-beta-version:
46+
name: "Test getting a specific CLI beta version"
47+
strategy:
48+
matrix:
49+
os: [ubuntu-latest, macos-latest]
50+
runs-on: ${{ matrix.os }}
51+
steps:
52+
- uses: actions/checkout@v3
53+
- name: Install 1Password CLI
54+
uses: ./ # 1password/install-cli-action@<version>
55+
with:
56+
version: 2.19.0-beta.01
57+
- name: Check CLI version
58+
run: ./test/assert-version.sh 2.19.0-beta.01

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 1Password
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1-
## Install 1Password CLI - GitHub Action
1+
<!-- Image sourced from https://blog.1password.com/1password-cli-2_0/ -->
2+
<img alt="" role="img" src="https://blog.1password.com/posts/2022/1password-cli-2.0/header.png"/>
23

3-
Install the 1Password CLI in your GitHub Actions pipeline.
4+
<div align="center">
5+
<h1>Install 1Password CLI GitHub Action</h1>
6+
<p>Install the <a href="https://developer.1password.com/docs/cli">1Password CLI</a> to access and manage your 1Password items in your GitHub Action runner.</p>
7+
<a href="#✨-quickstart">
8+
<img alt="Get started" src="https://user-images.githubusercontent.com/45081667/226940040-16d3684b-60f4-4d95-adb2-5757a8f1bc15.png" height="37"/>
9+
</a>
10+
</div>
11+
12+
---
13+
14+
# ✨ Quickstart
15+
16+
To install the latest version of the 1Password CLI: \
17+
(**Note:** `latest` version is installed by default, so you don't need to specify a version.)
18+
19+
```yaml
20+
- name: Install 1Password CLI
21+
uses: 1Password/install-cli@v1
22+
```
23+
24+
To install the latest beta version (i.e. `latest-beta`) of the 1Password CLI:
25+
26+
```yaml
27+
- name: Install 1Password CLI
28+
uses: 1Password/install-cli@v1
29+
with:
30+
version: latest-beta
31+
```
32+
33+
To install a specific version of the 1Password CLI:
34+
35+
```yaml
36+
- name: Install 1Password CLI
37+
uses: 1Password/install-cli@v1
38+
with:
39+
version: 2.18.0
40+
```
41+
42+
## ⚙️ Supported Runners
43+
44+
You can perform the action on Linux and macOS runners. Windows is not currently supported.
45+
46+
## 💙 Community & Support
47+
48+
- File an [issue](https://github.com/1Password/install-cli-action/issues) for bugs and feature requests.
49+
- Join the [Developer Slack workspace](https://join.slack.com/t/1password-devs/shared_invite/zt-1halo11ps-6o9pEv96xZ3LtX_VE0fJQA).
50+
- Subscribe to the [Developer Newsletter](https://1password.com/dev-subscribe/).
51+
52+
## 🔐 Security
53+
54+
1Password requests you practice responsible disclosure if you discover a vulnerability.
55+
56+
Please file requests via [**BugCrowd**](https://bugcrowd.com/agilebits).
57+
58+
For information about security practices, please visit our [Security homepage](https://bugcrowd.com/agilebits).

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Install 1Password CLI
2+
description: Install 1Password CLI in your pipeline
3+
author: 1Password
4+
branding:
5+
icon: lock
6+
color: blue
7+
inputs:
8+
version:
9+
description: Specify which 1Password CLI version to install. Defaults to "latest".
10+
default: "latest"
11+
runs:
12+
using: composite
13+
steps:
14+
- shell: bash
15+
env:
16+
OP_CLI_VERSION: ${{ inputs.version }}
17+
run: |
18+
${{ github.action_path }}/install-cli.sh

install-cli.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
set -e
3+
4+
CLI_URL="https://app-updates.agilebits.com/product_history/CLI2"
5+
6+
# Fetch the latest version of 1Password CLI (on stable or beta channel)
7+
get_latest_cli_version() {
8+
conditional_path="/beta/"
9+
if [ "$1" == "non_beta" ]; then
10+
conditional_path="!/beta/"
11+
fi
12+
# This long command parses the HTML page at "CLI_URL" and finds the latest CLI version
13+
# based on the release channel we're looking for (stable or beta).
14+
#
15+
# The ideal call (i.e. 'curl https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/Y -s | jq -r .version')
16+
# doesn't retrieve the latest CLI version on a channel basis.
17+
# If the latest release is stable and we want the latest beta, this command will return the stable still.
18+
OP_CLI_VERSION="v$(curl -s $CLI_URL | awk -v RS='<h3>|</h3>' 'NR % 2 == 0 {gsub(/[[:blank:]]+/, ""); gsub(/<span[^>]*>|<\/span>|[\r\n]+/, ""); gsub(/&nbsp;.*$/, ""); if (!'"$1"' && '"$conditional_path"'){print; '"$1"'=1;}}')"
19+
}
20+
21+
# Install op-cli
22+
install_op_cli() {
23+
OP_INSTALL_DIR="$(mktemp -d)"
24+
if [[ ! -d "$OP_INSTALL_DIR" ]]; then
25+
echo "Install dir $OP_INSTALL_DIR not found"
26+
exit 1
27+
fi
28+
echo "::debug::OP_INSTALL_DIR: ${OP_INSTALL_DIR}"
29+
30+
echo "Installing 1Password CLI version: ${OP_CLI_VERSION}"
31+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
32+
# Get architecture
33+
ARCH=$(uname -m)
34+
if [[ "$(getconf LONG_BIT)" = 32 ]]; then
35+
ARCH="386"
36+
elif [[ "$ARCH" == "x86_64" ]]; then
37+
ARCH="amd64"
38+
elif [[ "$ARCH" == "aarch64" ]]; then
39+
ARCH="arm64"
40+
fi
41+
42+
curl -sSfLo op.zip "https://cache.agilebits.com/dist/1P/op2/pkg/${OP_CLI_VERSION}/op_linux_${ARCH}_${OP_CLI_VERSION}.zip"
43+
unzip -od "$OP_INSTALL_DIR" op.zip && rm op.zip
44+
elif [[ "$OSTYPE" == "darwin"* ]]; then
45+
curl -sSfLo op.pkg "https://cache.agilebits.com/dist/1P/op2/pkg/${OP_CLI_VERSION}/op_apple_universal_${OP_CLI_VERSION}.pkg"
46+
pkgutil --expand op.pkg temp-pkg
47+
tar -xvf temp-pkg/op.pkg/Payload -C "$OP_INSTALL_DIR"
48+
rm -rf temp-pkg && rm op.pkg
49+
else
50+
echo "Install 1Password CLI GitHub Action isn't supported on this operating system yet: $OSTYPE."
51+
exit 1
52+
fi
53+
echo "$OP_INSTALL_DIR" >> "$GITHUB_PATH"
54+
}
55+
56+
# Main action of the script
57+
58+
if [[ "$OP_CLI_VERSION" == "latest" ]]; then
59+
get_latest_cli_version non_beta
60+
elif [[ "$OP_CLI_VERSION" == "latest-beta" ]]; then
61+
get_latest_cli_version beta
62+
else
63+
OP_CLI_VERSION="v$OP_CLI_VERSION"
64+
fi
65+
66+
install_op_cli

test/assert-version.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
OP_CLI_VERSION="$1"
5+
CLI_URL="https://app-updates.agilebits.com/product_history/CLI2"
6+
7+
get_latest_cli_version() {
8+
conditional_path="/beta/"
9+
if [ "$1" == "non_beta" ]; then
10+
conditional_path="!/beta/"
11+
fi
12+
# This long command parses the HTML page at "CLI_URL" and finds the latest CLI version
13+
# based on the release channel we're looking for (stable or beta).
14+
#
15+
# The ideal call (i.e. 'curl https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/Y -s | jq -r .version')
16+
# doesn't retrieve the latest CLI version on a channel basis.
17+
# If the latest release is stable and we want the latest beta, this command will return the stable still.
18+
OP_CLI_VERSION="$(curl -s $CLI_URL | awk -v RS='<h3>|</h3>' 'NR % 2 == 0 {gsub(/[[:blank:]]+/, ""); gsub(/<span[^>]*>|<\/span>|[\r\n]+/, ""); gsub(/&nbsp;.*$/, ""); if (!'"$1"' && '"$conditional_path"'){print; '"$1"'=1;}}')"
19+
}
20+
21+
if [ "$OP_CLI_VERSION" == "latest" ]; then
22+
get_latest_cli_version non_beta
23+
elif [ "$OP_CLI_VERSION" == "latest-beta" ]; then
24+
get_latest_cli_version beta
25+
fi
26+
27+
if [ "$(op --version)" != "$OP_CLI_VERSION" ]; then
28+
echo -e "Expected CLI version to be:\n$OP_CLI_VERSION\nBut got:\n$(op --version)"
29+
exit 1
30+
fi

0 commit comments

Comments
 (0)