-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
95 lines (78 loc) · 3.24 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env -S just --justfile
# ^ A shebang isn't required, but allows a justfile to be executed
# like a script, with `./justfile deps`, for example.
postman_collection_id := "4689407-29829c45-e619-4c12-910f-564ec8ccfda9-SVYrsdsG"
version := `cat VERSION`
api_spec_path := "priv/openapi_spec.yaml"
postman_path := "priv/postman_collection.json"
braze_swagger_path := "/tmp/braze_swagger.json"
build:
just deps
just refresh-postman
just fetch-api-info
just postman-to-openapi
just set-missing-content-types
just fixup-postman-spec
just regenerate
just prepare-readme
prepare-release:
just bump-version
just fixup-postman-spec
just regenerate
just prepare-readme
changed:
! git update-index --refresh
! git diff-index --quiet HEAD lib || git diff-index --quiet HEAD {{postman_path}}
@echo {{version}}
deps:
npm install
go install github.com/mikefarah/yq/v4@latest
fetch-api-info:
curl https://www.braze.com/docs/assets/js/swagger/braze_swagger.json | yq >| {{braze_swagger_path}}
SERVERS=`cat {{braze_swagger_path}} | jq '.servers'` yq -o json -i '.servers = env(SERVERS)' p2o.json
AUTH=`cat {{braze_swagger_path}} | jq '.components.securitySchemes'` yq -o json -i '.auth = env(AUTH)' p2o.json
refresh-postman:
curl "https://www.postman.com/collections/{{postman_collection_id}}" | jq >| {{postman_path}}
sed -i 's/\}\} \//\}\}\//g' {{postman_path}}
jq -r '.info.description' {{postman_path}} >| API_DESCRIPTION.md
postman-to-openapi:
npm exec p2o -- {{postman_path}} -o p2o.json | yq -P >| {{api_spec_path}}
fixup-postman-spec:
VERSION=`cat VERSION` yq -iP '.info.version = strenv(VERSION)' {{api_spec_path}}
yq -iP '.info.description = "Braze HTTP API (generated from Braze Postman Collection)"' {{api_spec_path}}
# 2023-02-03 - Postman collection is missing Content types for these resources, stub them with an empty string
set-missing-content-types:
yq -iP '.paths."/catalogs/{catalog_name}/items".patch.requestBody.content = {"*/*": {"schema": {"type": "string"}}}' {{api_spec_path}}
yq -iP '.paths."/catalogs".post.requestBody.content = {"*/*": {"schema": {"type": "string"}}}' {{api_spec_path}}
yq -iP '.paths."/catalogs/{catalog_name}/items".post.requestBody.content = {"*/*": {"schema": {"type": "string"}}}' {{api_spec_path}}
bump-version:
@echo {{version}}
awk -i inplace -F. '/[0-9]+\./{$NF++;print}BEGIN{OFS="."}' VERSION
@echo "Openapi Spec has changed. Bumping Version from {{version}} to `cat VERSION`"
regenerate:
npx "@openapitools/openapi-generator-cli" generate \
--input-spec={{api_spec_path}} \
--generator-name=elixir \
--skip-validate-spec \
--config=priv/openapi_config.yaml
just elixir
mix format
prepare-readme:
printf "\n" >> README.md
cat USAGE.md >> README.md
printf "\n" >> README.md
cat DEVELOPMENT.md >> README.md
elixir:
mix local.hex --force
mix deps.get
publish:elixir
#!/usr/bin/env bash
if ! git diff-index --quiet HEAD --; then
git add .
git commit -am "🤖 Version Bump to `cat VERSION`"
mix deps.get
mix hex.publish --yes
git push
else
echo "No Changes to publish"
fi