Skip to content

Commit 17d5c48

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

File tree

3 files changed

+113
-19
lines changed

3 files changed

+113
-19
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: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,87 @@ jobs:
1414
node-version: 20
1515
- run: npm ci
1616
- run: npm test
17+
1718
test-with-output-secrets:
18-
if: |
19-
github.ref == 'refs/heads/main' ||
20-
(
21-
github.event_name == 'pull_request' &&
22-
github.event.pull_request.head.repo.full_name == github.repository
23-
)
19+
strategy:
20+
matrix:
21+
os: [ubuntu-latest, macos-latest, windows-latest]
22+
version: [latest, latest-beta, 2.30.0, 2.30.0-beta.03]
23+
auth: [connect, service-account]
24+
exclude:
25+
- os: macos-latest
26+
auth: connect
27+
- os: windows-latest
28+
auth: connect
2429
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2
2530
secrets: inherit
2631
with:
32+
os: ${{ matrix.os }}
33+
version: ${{ matrix.version }}
34+
auth: ${{ matrix.auth }}
2735
secret: op://acceptance-tests/test-secret/password
2836
secret-in-section: op://acceptance-tests/test-secret/test-section/password
2937
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
3038
export-env: false
31-
test-with-export-env:
3239
if: |
3340
github.ref == 'refs/heads/main' ||
3441
(
3542
github.event_name == 'pull_request' &&
3643
github.event.pull_request.head.repo.full_name == github.repository
3744
)
45+
46+
test-with-export-env:
47+
strategy:
48+
matrix:
49+
os: [ubuntu-latest, macos-latest, windows-latest]
50+
version: [latest, latest-beta, 2.30.0, 2.30.0-beta.03]
51+
auth: [connect, service-account]
52+
exclude:
53+
- os: macos-latest
54+
auth: connect
55+
- os: windows-latest
56+
auth: connect
3857
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2
3958
secrets: inherit
4059
with:
60+
os: ${{ matrix.os }}
61+
version: ${{ matrix.version }}
62+
auth: ${{ matrix.auth }}
4163
secret: op://acceptance-tests/test-secret/password
4264
secret-in-section: op://acceptance-tests/test-secret/test-section/password
4365
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
4466
export-env: true
45-
test-references-with-ids:
4667
if: |
4768
github.ref == 'refs/heads/main' ||
4869
(
4970
github.event_name == 'pull_request' &&
5071
github.event.pull_request.head.repo.full_name == github.repository
5172
)
73+
74+
test-references-with-ids:
75+
strategy:
76+
matrix:
77+
os: [ubuntu-latest, macos-latest, windows-latest]
78+
version: [latest, latest-beta, 2.30.0, 2.30.0-beta.03]
79+
auth: [connect, service-account]
80+
exclude:
81+
- os: macos-latest
82+
auth: connect
83+
- os: windows-latest
84+
auth: connect
5285
uses: 1password/load-secrets-action/.github/workflows/acceptance-test.yml@vzt/windows-support2
5386
secrets: inherit
5487
with:
88+
os: ${{ matrix.os }}
89+
version: ${{ matrix.version }}
90+
auth: ${{ matrix.auth }}
5591
secret: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password
5692
secret-in-section: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/Section_tco6nsqycj6jcbyx63h5isxcny/doxu3mhkozcznnk5vjrkpdqayy
5793
multiline-secret: op://v5pz6venw4roosmkzdq2nhpv6u/ghtz3jvcc6dqmzc53d3r3eskge/notesPlain
5894
export-env: false
95+
if: |
96+
github.ref == 'refs/heads/main' ||
97+
(
98+
github.event_name == 'pull_request' &&
99+
github.event.pull_request.head.repo.full_name == github.repository
100+
)

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)