Skip to content

Commit f17306b

Browse files
authored
Merge pull request #4 from seek-oss/namespace-var-names
Namespace var names
2 parents 08265cb + 28d3470 commit f17306b

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

.buildkite/pipeline.yml

-15
This file was deleted.

.github/workflows/main.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Buildkite plugins test actions
2+
on: push
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- name: Lint
9+
run: docker-compose run lint
10+
- name: Tests
11+
run: docker-compose run tests

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Private NPM Buildkite Plugin [![Build status](https://badge.buildkite.com/705414e5df1533fbc18a2dda1305ec015282575a87edb1e0c1.svg)](https://buildkite.com/seek/private-npm-buildkite-plugin)
1+
# Private NPM Buildkite Plugin
2+
3+
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fseek-oss%2Fprivate-npm-buildkite-plugin%2Fbadge&style=flat)](https://actions-badge.atrox.dev/seek-oss/private-npm-buildkite-plugin/goto)
4+
[![GitHub Release](https://img.shields.io/github/release/seek-oss/private-npm-buildkite-plugin.svg)](https://github.com/seek-oss/private-npm-buildkite-plugin/releases)
5+
26

37
A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) to allow pipeline steps to easily install
48
private packages from an [npm](https://www.npmjs.com) repository.
@@ -13,7 +17,7 @@ To read the value from an environment variable named `MY_TOKEN` when the plugin
1317
steps:
1418
- command: yarn install
1519
plugins:
16-
- seek-oss/private-npm#v1.1.1:
20+
- seek-oss/private-npm#v1.1.2:
1721
env: "MY_TOKEN"
1822
```
1923
@@ -23,7 +27,7 @@ To read the value from a file named `my_token_file`, use the `file` field.
2327
steps:
2428
- command: yarn install
2529
plugins:
26-
- seek-oss/private-npm#v1.1.1:
30+
- seek-oss/private-npm#v1.1.2:
2731
file: "my_token_file"
2832
```
2933

@@ -35,7 +39,7 @@ approach is discoraged in favour of using with the `env` or `file` fields. This
3539
steps:
3640
- command: yarn install
3741
plugins:
38-
- seek-oss/private-npm#v1.1.1:
42+
- seek-oss/private-npm#v1.1.2:
3943
token: ${MY_TOKEN}
4044
```
4145

@@ -46,7 +50,7 @@ You can also specify a custom npm registry if you are using your own mirror.
4650
steps:
4751
- command: yarn install
4852
plugins:
49-
- seek-oss/private-npm#v1.1.1:
53+
- seek-oss/private-npm#v1.1.2:
5054
env: "MY_TOKEN"
5155
registry: //myprivatenpm.com/
5256
```
@@ -62,6 +66,9 @@ The value of the NPM token will be read from the agent environment when the plug
6266
around cases where eager binding of variables in `pipeline.yml` means some variables are not present in the
6367
environment when the configuration file is parsed.
6468

69+
> **NOTE** : Beware of using `NPM_TOKEN` as the name for the environment variable. When using that name the variable
70+
> is unstable and has a tedency to return an empty string in the context of this plugin.
71+
6572
### `file` (optional)
6673

6774
The value of the NPM token will be read from a file on the agent when the plugin executes. This is useful when working

docker-compose.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ services:
33
tests:
44
image: buildkite/plugin-tester
55
volumes:
6-
- ".:/plugin"
6+
- ".:/plugin"
7+
lint:
8+
image: buildkite/plugin-linter
9+
command: ['--name', 'seek-oss/private-npm']
10+
volumes:
11+
- ".:/plugin:ro"

hooks/pre-command

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
set -euo pipefail
33
IFS=$'\n\t'
44

5-
REGISTRY=${BUILDKITE_PLUGIN_PRIVATE_NPM_REGISTRY:-'//registry.npmjs.org/'}
6-
TOKEN=${BUILDKITE_PLUGIN_PRIVATE_NPM_TOKEN:-''}
7-
FILE=${BUILDKITE_PLUGIN_PRIVATE_NPM_FILE:-''}
8-
ENV=${BUILDKITE_PLUGIN_PRIVATE_NPM_ENV:-''}
5+
SEEK_OSS_PRIVATE_NPM_REGISTRY=${BUILDKITE_PLUGIN_PRIVATE_NPM_REGISTRY:-'//registry.npmjs.org/'}
6+
SEEK_OSS_PRIVATE_NPM_TOKEN=${BUILDKITE_PLUGIN_PRIVATE_NPM_TOKEN:-''}
7+
SEEK_OSS_PRIVATE_NPM_FILE=${BUILDKITE_PLUGIN_PRIVATE_NPM_FILE:-''}
8+
SEEK_OSS_PRIVATE_NPM_ENV=${BUILDKITE_PLUGIN_PRIVATE_NPM_ENV:-''}
99

10-
if { [[ -n "${FILE}" ]] && [[ -n "${ENV}" ]]; } \
11-
|| { [[ -n "${FILE}" ]] && [[ -n "${TOKEN}" ]]; } \
12-
|| { [[ -n "${TOKEN}" ]] && [[ -n "${ENV}" ]]; }
10+
if { [[ -n "${SEEK_OSS_PRIVATE_NPM_FILE}" ]] && [[ -n "${SEEK_OSS_PRIVATE_NPM_ENV}" ]]; } \
11+
|| { [[ -n "${SEEK_OSS_PRIVATE_NPM_FILE}" ]] && [[ -n "${SEEK_OSS_PRIVATE_NPM_TOKEN}" ]]; } \
12+
|| { [[ -n "${SEEK_OSS_PRIVATE_NPM_TOKEN}" ]] && [[ -n "${SEEK_OSS_PRIVATE_NPM_ENV}" ]]; }
1313
then
1414
echo ':no_entry_sign: :npm: :package: Failed! Only one of file, env or token parameters may be set'
1515
exit 1
1616
fi
1717

18-
if [[ -n "${FILE}" ]]
18+
if [[ -n "${SEEK_OSS_PRIVATE_NPM_FILE}" ]]
1919
then
20-
TOKEN=$(cat "${FILE}")
21-
elif [[ -n "${ENV}" ]]
20+
SEEK_OSS_PRIVATE_NPM_TOKEN=$(cat "${SEEK_OSS_PRIVATE_NPM_FILE}")
21+
elif [[ -n "${SEEK_OSS_PRIVATE_NPM_ENV}" ]]
2222
then
23-
TOKEN="${!ENV}"
23+
SEEK_OSS_PRIVATE_NPM_TOKEN="${!SEEK_OSS_PRIVATE_NPM_ENV}"
2424
fi
2525

26-
if [[ -z $TOKEN ]]
26+
if [[ -z $SEEK_OSS_PRIVATE_NPM_TOKEN ]]
2727
then
2828
echo ':no_entry_sign: :npm: :package: Failed! A valid NPM_TOKEN could not be determined'
2929
exit 1
@@ -32,6 +32,6 @@ fi
3232
echo '--- Setting up access for :no_entry_sign: :npm: :package:'
3333

3434
cat > .npmrc << EOF
35-
${REGISTRY}:_authToken=${TOKEN}
35+
${SEEK_OSS_PRIVATE_NPM_REGISTRY}:_authToken=${SEEK_OSS_PRIVATE_NPM_TOKEN}
3636
save-exact=true
3737
EOF

0 commit comments

Comments
 (0)