Skip to content

Commit 6758e26

Browse files
Add more tests to check that action works correctly with provided stable or beta version
1 parent 5184a22 commit 6758e26

File tree

3 files changed

+108
-14
lines changed

3 files changed

+108
-14
lines changed

.github/workflows/acceptance-test.yml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ on:
1515
export-env:
1616
required: true
1717
type: boolean
18+
version:
19+
required: false
20+
type: string
21+
default: "latest"
22+
os:
23+
required: true
24+
type: string
25+
default: "ubuntu-latest"
26+
auth:
27+
required: true
28+
type: string
1829

1930
jobs:
2031
acceptance-test:
21-
strategy:
22-
matrix:
23-
os: [ubuntu-latest, macos-latest, windows-latest]
24-
auth: [connect, service-account]
25-
exclude:
26-
- os: macos-latest
27-
auth: connect
28-
runs-on: ${{ matrix.os }}
32+
runs-on: ${{ inputs.os }}
2933
steps:
3034
- name: Base checkout
3135
uses: actions/checkout@v4
@@ -50,32 +54,50 @@ jobs:
5054
github.event.client_payload.slash_command.args.named.sha
5155
)
5256
- name: Launch 1Password Connect instance
53-
if: ${{ matrix.auth == 'connect' }}
57+
if: ${{ inputs.auth == 'connect' }}
5458
env:
5559
OP_CONNECT_CREDENTIALS: ${{ secrets.OP_CONNECT_CREDENTIALS }}
5660
run: |
5761
echo "$OP_CONNECT_CREDENTIALS" > 1password-credentials.json
5862
docker compose -f tests/fixtures/docker-compose.yml up -d && sleep 10
5963
- name: Configure Service account
60-
if: ${{ matrix.auth == 'service-account' }}
64+
if: ${{ inputs.auth == 'service-account' }}
6165
uses: ./configure
6266
with:
6367
service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
68+
- name: Verify Service Account env var is set
69+
if: ${{ inputs.auth == 'service-account' }}
70+
shell: bash
71+
run: |
72+
if [ -z "${OP_SERVICE_ACCOUNT_TOKEN}" ]; then
73+
echo "OP_SERVICE_ACCOUNT_TOKEN environment variable is not set" >&2
74+
exit 1
75+
fi
6476
- name: Configure 1Password Connect
65-
if: ${{ matrix.auth == 'connect' }}
77+
if: ${{ inputs.auth == 'connect' }}
6678
uses: ./configure # 1password/load-secrets-action/configure@<version>
6779
with:
6880
connect-host: http://localhost:8080
6981
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
82+
- name: Verify Connect env vars are set
83+
if: ${{ inputs.auth == 'connect' }}
84+
run: |
85+
if [ -z "$OP_CONNECT_HOST" ] || [ -z "$OP_CONNECT_TOKEN" ]; then
86+
echo "OP_CONNECT_HOST or OP_CONNECT_TOKEN environment variables are not set" >&2
87+
exit 1
88+
fi
7089
- name: Load secrets
7190
id: load_secrets
7291
uses: ./ # 1password/load-secrets-action@<version>
7392
with:
93+
version: ${{ inputs.version }}
7494
export-env: ${{ inputs.export-env }}
7595
env:
7696
SECRET: ${{ inputs.secret }}
7797
SECRET_IN_SECTION: ${{ inputs.secret-in-section }}
7898
MULTILINE_SECRET: ${{ inputs.multiline-secret }}
99+
- name: Verify installed op cli version
100+
run: ./tests/assert-cli-version.sh ${{ inputs.version }}
79101
- name: Assert test secret values [step output]
80102
if: ${{ !inputs.export-env }}
81103
env:

.github/workflows/test.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,86 @@ jobs:
1414
node-version: 20
1515
- run: npm ci
1616
- run: npm test
17+
1718
test-with-output-secrets:
1819
if: |
1920
github.ref == 'refs/heads/main' ||
2021
(
2122
github.event_name == 'pull_request' &&
2223
github.event.pull_request.head.repo.full_name == github.repository
2324
)
24-
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2
25+
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')
2526
secrets: inherit
27+
strategy:
28+
matrix:
29+
os: [ ubuntu-latest, macos-latest, windows-latest ]
30+
version: [ latest, latest-beta, 2.30.0, 2.30.0-beta.03 ]
31+
auth: [ connect, service-account ]
32+
exclude:
33+
- os: macos-latest
34+
auth: connect
35+
- os: windows-latest
36+
auth: connect
2637
with:
38+
os: ${{ matrix.os }}
39+
version: ${{ matrix.version }}
40+
auth: ${{ matrix.auth }}
2741
secret: op://acceptance-tests/test-secret/password
2842
secret-in-section: op://acceptance-tests/test-secret/test-section/password
2943
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
3044
export-env: false
45+
3146
test-with-export-env:
3247
if: |
3348
github.ref == 'refs/heads/main' ||
3449
(
3550
github.event_name == 'pull_request' &&
3651
github.event.pull_request.head.repo.full_name == github.repository
3752
)
38-
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2
53+
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')
3954
secrets: inherit
55+
strategy:
56+
matrix:
57+
os: [ ubuntu-latest, macos-latest, windows-latest ]
58+
version: [ latest, latest-beta, 2.30.0, 2.30.0-beta.03 ]
59+
auth: [ connect, service-account ]
60+
exclude:
61+
- os: macos-latest
62+
auth: connect
63+
- os: windows-latest
64+
auth: connect
4065
with:
66+
os: ${{ matrix.os }}
67+
version: ${{ matrix.version }}
68+
auth: ${{ matrix.auth }}
4169
secret: op://acceptance-tests/test-secret/password
4270
secret-in-section: op://acceptance-tests/test-secret/test-section/password
4371
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
4472
export-env: true
73+
4574
test-references-with-ids:
4675
if: |
4776
github.ref == 'refs/heads/main' ||
4877
(
4978
github.event_name == 'pull_request' &&
5079
github.event.pull_request.head.repo.full_name == github.repository
5180
)
52-
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2
81+
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')
5382
secrets: inherit
83+
strategy:
84+
matrix:
85+
os: [ ubuntu-latest, macos-latest, windows-latest ]
86+
version: [ latest, latest-beta, 2.30.0, 2.30.0-beta.03 ]
87+
auth: [ connect, service-account ]
88+
exclude:
89+
- os: macos-latest
90+
auth: connect
91+
- os: windows-latest
92+
auth: connect
5493
with:
94+
os: ${{ matrix.os }}
95+
version: ${{ matrix.version }}
96+
auth: ${{ matrix.auth }}
5597
secret: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password
5698
secret-in-section: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/Section_tco6nsqycj6jcbyx63h5isxcny/doxu3mhkozcznnk5vjrkpdqayy
5799
multiline-secret: op://v5pz6venw4roosmkzdq2nhpv6u/ghtz3jvcc6dqmzc53d3r3eskge/notesPlain

tests/assert-cli-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)