Compare commits

..

17 Commits

Author SHA1 Message Date
Volodymyr Zotov
c29e37a48a Update install-cli-action package 2025-07-30 15:47:37 -05:00
Volodymyr Zotov
54f4c31d4e Update build 2025-07-30 14:57:42 -05:00
Volodymyr Zotov
44eaa0c9eb Revert .gitignore and tsconfig.json 2025-07-30 14:45:02 -05:00
Volodymyr Zotov
6758e26159 Add more tests to check that action works correctly with provided stable or beta version 2025-07-30 14:45:01 -05:00
Volodymyr Zotov
5184a22826 Fix lint errors 2025-07-30 12:56:39 -05:00
Volodymyr Zotov
773e006869 Use core lib to set env vars 2025-07-30 12:54:29 -05:00
Volodymyr Zotov
a241f7e820 Get inputs using core library 2025-07-30 12:53:17 -05:00
Volodymyr Zotov
32f94abf82 Write to GITHUB_ENV manually 2025-07-30 12:49:44 -05:00
Volodymyr Zotov
9de113048d Re-write configure action in JS 2025-07-30 12:43:16 -05:00
Volodymyr Zotov
4923638555 Temporary point to the current branch to enable job to run on Windows 2025-07-30 11:09:03 -05:00
Volodymyr Zotov
2195738903 Trigger workflow for updated matrix 2025-07-30 11:06:10 -05:00
Volodymyr Zotov
f8405764b3 Run tests on Windows platform 2025-07-30 11:00:45 -05:00
Volodymyr Zotov
6b6b0dc705 Update export jest.config as package now of type commonjs instead of module 2025-07-30 10:59:07 -05:00
Volodymyr Zotov
29819e3c8f Fix lint 2025-07-30 10:59:06 -05:00
Volodymyr Zotov
7e497dcd83 Make module commonjs 2025-07-30 10:59:06 -05:00
Volodymyr Zotov
aa7dbab2b7 Remove package.json
As ncc uses commonjs bundle type and we import `install-cli-action` which is also commonjs, we should not set `type: module` in the package.json so it doesn't break the load-secrets-action bundle. Therefore, we can safely remove it at all.

Revert package.json
2025-07-30 10:59:06 -05:00
Volodymyr Zotov
80da714262 Use install-cli-action to enable windows support 2025-07-30 10:59:06 -05:00
14 changed files with 34109 additions and 6467 deletions

View File

@@ -15,7 +15,7 @@ on:
export-env: export-env:
required: true required: true
type: boolean type: boolean
cli-version: version:
required: false required: false
type: string type: string
default: "latest" default: "latest"
@@ -90,12 +90,14 @@ jobs:
id: load_secrets id: load_secrets
uses: ./ # 1password/load-secrets-action@<version> uses: ./ # 1password/load-secrets-action@<version>
with: with:
cli-version: ${{ inputs.cli-version }} version: ${{ inputs.version }}
export-env: ${{ inputs.export-env }} export-env: ${{ inputs.export-env }}
env: env:
SECRET: ${{ inputs.secret }} SECRET: ${{ inputs.secret }}
SECRET_IN_SECTION: ${{ inputs.secret-in-section }} SECRET_IN_SECTION: ${{ inputs.secret-in-section }}
MULTILINE_SECRET: ${{ inputs.multiline-secret }} MULTILINE_SECRET: ${{ inputs.multiline-secret }}
- name: Verify installed op cli version
run: ./tests/assert-cli-version.sh ${{ inputs.version }}
- name: Assert test secret values [step output] - name: Assert test secret values [step output]
if: ${{ !inputs.export-env }} if: ${{ !inputs.export-env }}
env: env:

View File

@@ -22,13 +22,13 @@ jobs:
github.event_name == 'pull_request' && github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository github.event.pull_request.head.repo.full_name == github.repository
) )
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/rename-version-input # TODO: temporary point to this branch so tests can run with update input uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2 #TODO: after merge, this to main, revert to consume yml file from main (delete '@vzt/windows-support2')
secrets: inherit secrets: inherit
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ ubuntu-latest, macos-latest, windows-latest ]
cli-version: [latest, latest-beta, 2.30.0, 2.30.0-beta.03] version: [ latest, latest-beta, 2.30.0, 2.30.0-beta.03 ]
auth: [connect, service-account] auth: [ connect, service-account ]
exclude: exclude:
- os: macos-latest - os: macos-latest
auth: connect auth: connect
@@ -36,7 +36,7 @@ jobs:
auth: connect auth: connect
with: with:
os: ${{ matrix.os }} os: ${{ matrix.os }}
cli-version: ${{ matrix.cli-version }} version: ${{ matrix.version }}
auth: ${{ matrix.auth }} auth: ${{ matrix.auth }}
secret: op://acceptance-tests/test-secret/password secret: op://acceptance-tests/test-secret/password
secret-in-section: op://acceptance-tests/test-secret/test-section/password secret-in-section: op://acceptance-tests/test-secret/test-section/password
@@ -50,13 +50,13 @@ jobs:
github.event_name == 'pull_request' && github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository github.event.pull_request.head.repo.full_name == github.repository
) )
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/rename-version-input # TODO: temporary point to this branch so tests can run with update input uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2 #TODO: after merge, this to main, revert to consume yml file from main (delete '@vzt/windows-support2')
secrets: inherit secrets: inherit
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ ubuntu-latest, macos-latest, windows-latest ]
cli-version: [latest, latest-beta, 2.30.0, 2.30.0-beta.03] version: [ latest, latest-beta, 2.30.0, 2.30.0-beta.03 ]
auth: [connect, service-account] auth: [ connect, service-account ]
exclude: exclude:
- os: macos-latest - os: macos-latest
auth: connect auth: connect
@@ -64,7 +64,7 @@ jobs:
auth: connect auth: connect
with: with:
os: ${{ matrix.os }} os: ${{ matrix.os }}
cli-version: ${{ matrix.cli-version }} version: ${{ matrix.version }}
auth: ${{ matrix.auth }} auth: ${{ matrix.auth }}
secret: op://acceptance-tests/test-secret/password secret: op://acceptance-tests/test-secret/password
secret-in-section: op://acceptance-tests/test-secret/test-section/password secret-in-section: op://acceptance-tests/test-secret/test-section/password
@@ -78,13 +78,13 @@ jobs:
github.event_name == 'pull_request' && github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository github.event.pull_request.head.repo.full_name == github.repository
) )
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/rename-version-input # TODO: temporary point to this branch so tests can run with update input uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2 #TODO: after merge, this to main, revert to consume yml file from main (delete '@vzt/windows-support2')
secrets: inherit secrets: inherit
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ ubuntu-latest, macos-latest, windows-latest ]
cli-version: [latest, latest-beta, 2.30.0, 2.30.0-beta.03] version: [ latest, latest-beta, 2.30.0, 2.30.0-beta.03 ]
auth: [connect, service-account] auth: [ connect, service-account ]
exclude: exclude:
- os: macos-latest - os: macos-latest
auth: connect auth: connect
@@ -92,7 +92,7 @@ jobs:
auth: connect auth: connect
with: with:
os: ${{ matrix.os }} os: ${{ matrix.os }}
cli-version: ${{ matrix.cli-version }} version: ${{ matrix.version }}
auth: ${{ matrix.auth }} auth: ${{ matrix.auth }}
secret: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password secret: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password
secret-in-section: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/Section_tco6nsqycj6jcbyx63h5isxcny/doxu3mhkozcznnk5vjrkpdqayy secret-in-section: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/Section_tco6nsqycj6jcbyx63h5isxcny/doxu3mhkozcznnk5vjrkpdqayy

View File

@@ -23,40 +23,16 @@ Read more on the [1Password Developer Portal](https://developer.1password.com/do
## ✨ Quickstart ## ✨ Quickstart
### Export secrets as a step's output (recommended)
```yml ```yml
on: push on: push
jobs: jobs:
hello-world: hello-world:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Load secret - name: Load secret
id: load_secret uses: 1password/load-secrets-action@v2
uses: 1password/load-secrets-action@v3
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
SECRET: op://app-cicd/hello-world/secret
- name: Print masked secret
run: 'echo "Secret: ${{ steps.load_secrets.outputs.SECRET }}"'
# Prints: Secret: ***
```
### Export secrets as env variables
```yml
on: push
jobs:
hello-world:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Load secret
uses: 1password/load-secrets-action@v3
with: with:
# Export loaded secrets as environment variables # Export loaded secrets as environment variables
export-env: true export-env: true

View File

@@ -5,15 +5,15 @@ branding:
icon: lock icon: lock
color: blue color: blue
inputs: inputs:
version:
description: Version of the 1Password CLI to install
default: latest
unset-previous: unset-previous:
description: Whether to unset environment variables populated by 1Password in earlier job steps description: Whether to unset environment variables populated by 1Password in earlier job steps
default: "false" default: "false"
export-env: export-env:
description: Export the secrets as environment variables description: Export the secrets as environment variables
default: "false" default: "true"
cli-version:
description: Specify which 1Password CLI version to install. Defaults to "latest".
default: "latest"
runs: runs:
using: "node20" using: "node20"
main: "dist/index.js" main: "dist/index.js"

View File

@@ -25,4 +25,4 @@ const jestConfig = {
verbose: true, verbose: true,
}; };
export default jestConfig; module.exports = jestConfig;

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +0,0 @@
{
"type": "commonjs"
}

39007
dist/index.js vendored

File diff suppressed because one or more lines are too long

3
dist/package.json vendored
View File

@@ -1,3 +0,0 @@
{
"type": "commonjs"
}

46
install_cli.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
set -e
# Install op-cli
install_op_cli() {
# Create a temporary directory where the CLI is installed
OP_INSTALL_DIR="$(mktemp -d)"
if [[ ! -d "$OP_INSTALL_DIR" ]]; then
echo "Install dir $OP_INSTALL_DIR not found"
exit 1
fi
echo "::debug::OP_INSTALL_DIR: ${OP_INSTALL_DIR}"
# Get the latest stable version of the CLI
CLI_VERSION="v$(curl https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/N -s | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Get runner's architecture
ARCH=$(uname -m)
if [[ "$(getconf LONG_BIT)" = 32 ]]; then
ARCH="386"
elif [[ "$ARCH" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$ARCH" == "aarch64" ]]; then
ARCH="arm64"
fi
if [[ "$ARCH" != "386" ]] && [[ "$ARCH" != "amd64" ]] && [[ "$ARCH" != "arm" ]] && [[ "$ARCH" != "arm64" ]]; then
echo "Unsupported architecture for the 1Password CLI: $ARCH."
exit 1
fi
curl -sSfLo op.zip "https://cache.agilebits.com/dist/1P/op2/pkg/${CLI_VERSION}/op_linux_${ARCH}_${CLI_VERSION}.zip"
unzip -od "$OP_INSTALL_DIR" op.zip && rm op.zip
elif [[ "$OSTYPE" == "darwin"* ]]; then
curl -sSfLo op.pkg "https://cache.agilebits.com/dist/1P/op2/pkg/${CLI_VERSION}/op_apple_universal_${CLI_VERSION}.pkg"
pkgutil --expand op.pkg temp-pkg
tar -xvf temp-pkg/op.pkg/Payload -C "$OP_INSTALL_DIR"
rm -rf temp-pkg && rm op.pkg
else
echo "Operating system not supported yet for this GitHub Action: $OSTYPE."
exit 1
fi
}
install_op_cli

524
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
"name": "load-secrets-action", "name": "load-secrets-action",
"version": "2.0.0", "version": "2.0.0",
"description": "Load Secrets from 1Password", "description": "Load Secrets from 1Password",
"type": "commonjs",
"main": "dist/index.js", "main": "dist/index.js",
"directories": { "directories": {
"test": "tests" "test": "tests"
@@ -9,7 +10,6 @@
"scripts": { "scripts": {
"build": "ncc build ./src/index.ts", "build": "ncc build ./src/index.ts",
"build:configure": "ncc build ./configure/index.js -o ./configure/dist", "build:configure": "ncc build ./configure/index.js -o ./configure/dist",
"build:all": "npm run build && npm run build:configure",
"format": "prettier --ignore-path ./config/.prettierignore", "format": "prettier --ignore-path ./config/.prettierignore",
"format:check": "npm run format -- --check ./", "format:check": "npm run format -- --check ./",
"format:write": "npm run format -- --write ./", "format:write": "npm run format -- --write ./",
@@ -40,10 +40,11 @@
}, },
"homepage": "https://github.com/1Password/load-secrets-action#readme", "homepage": "https://github.com/1Password/load-secrets-action#readme",
"dependencies": { "dependencies": {
"@1password/install-cli-action": "github:1password/install-cli-action#vzt/export-install-function",
"@1password/op-js": "^0.1.11", "@1password/op-js": "^0.1.11",
"@actions/core": "^1.10.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"op-cli-installer": "github:1Password/op-cli-installer#e6c1c758bc3339e5fe9b06255728039f688f73fa" "@actions/tool-cache": "^2.0.2"
}, },
"devDependencies": { "devDependencies": {
"@1password/eslint-config": "^4.3.1", "@1password/eslint-config": "^4.3.1",

View File

@@ -1,6 +1,5 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import { validateCli } from "@1password/op-js"; import { validateCli } from "@1password/op-js";
import { installCliOnGithubActionRunner } from "op-cli-installer";
import { loadSecrets, unsetPrevious, validateAuth } from "./utils"; import { loadSecrets, unsetPrevious, validateAuth } from "./utils";
const loadSecretsAction = async () => { const loadSecretsAction = async () => {
@@ -44,9 +43,10 @@ const installCLI = async (): Promise<void> => {
// If there's no CLI installed, then validateCli will throw an error, which we will use // If there's no CLI installed, then validateCli will throw an error, which we will use
// as an indicator that we need to execute the installation script. // as an indicator that we need to execute the installation script.
await validateCli().catch(async () => { await validateCli().catch(async () => {
// defaults to `latest` if not provided // eslint-disable-next-line
const cliVersion = core.getInput("cli-version"); const { install } = require("@1password/install-cli-action");
await installCliOnGithubActionRunner(cliVersion); // eslint-disable-next-line @typescript-eslint/no-unsafe-call
await install();
}); });
}; };

30
tests/assert-cli-version.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
set -e
OP_CLI_VERSION="$1"
CLI_URL="https://app-updates.agilebits.com/product_history/CLI2"
get_latest_cli_version() {
conditional_path="/beta/"
if [ "$1" == "non_beta" ]; then
conditional_path="!/beta/"
fi
# This long command parses the HTML page at "CLI_URL" and finds the latest CLI version
# based on the release channel we're looking for (stable or beta).
#
# The ideal call (i.e. 'curl https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/Y -s | jq -r .version')
# doesn't retrieve the latest CLI version on a channel basis.
# If the latest release is stable and we want the latest beta, this command will return the stable still.
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;}}')"
}
if [ "$OP_CLI_VERSION" == "latest" ]; then
get_latest_cli_version non_beta
elif [ "$OP_CLI_VERSION" == "latest-beta" ]; then
get_latest_cli_version beta
fi
if [ "$(op --version)" != "$OP_CLI_VERSION" ]; then
echo -e "Expected CLI version to be:\n$OP_CLI_VERSION\nBut got:\n$(op --version)"
exit 1
fi