forked from cdklabs/cdk-cicd-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.codeartifact.yml
175 lines (158 loc) · 8 KB
/
Taskfile.codeartifact.yml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
version: '3'
vars:
SECRET_ID: 'cdk-cicd-wrapper'
DOMAIN: 'cdk-cicd-wrapper'
REPOSITORY: 'cdk-cicd-wrapper'
tasks:
publish:
desc: Run tests and release
deps:
- unpublish
preconditions:
- sh: npm config get @cdklabs:registry | grep codeartifact
msg: "CodeArtifact repository has to be set up for test release. Use 'task codeartifact:login'."
cmds:
- task build
- task: publish:pipeline
- task: publish:cli
- task: publish:projen
unpublish:
desc: Unpublish all package versions
cmds:
- task: unpublish:package
vars:
PACKAGE: 'cdk-cicd-wrapper-cli'
- task: unpublish:package
vars:
PACKAGE: 'cdk-cicd-wrapper'
- task: unpublish:package
vars:
PACKAGE: 'cdk-cicd-wrapper-projen'
unpublish:package:
internal: true
desc: Unpublish a package version
preconditions:
- sh: npm config get @cdklabs:registry | grep codeartifact
msg: "CodeArtifact repository has to be set up for test release. Use 'task codeartifact:login'."
requires:
vars:
- PACKAGE
vars:
NAMESPACE: 'cdklabs'
VERSION:
sh: npm view @{{.NAMESPACE}}/{{.PACKAGE}} version 2> /dev/null || true
silent: true
cmds:
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}delete-package-versions --domain {{.DOMAIN}} --repository {{.REPOSITORY}} --format npm --package {{.PACKAGE}} --namespace {{.NAMESPACE}} --versions {{.VERSION}} {{with .AWS_REGION}} --region {{.}} {{end}} &> /dev/null
- echo "Unpublished version {{.VERSION}} of package @{{.NAMESPACE}}/{{.PACKAGE}}."
status:
- '[ ! $(npm view @{{.NAMESPACE}}/{{.PACKAGE}} version 2> /dev/null) ]'
- '[ ! $(aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-package-version --domain {{.DOMAIN}} --repository {{.REPOSITORY}} --format npm --package {{.PACKAGE}} --namespace {{.NAMESPACE}} --version {{.VERSION}} {{with .AWS_REGION}} --region {{.}} {{end}}) ]'
publish:pipeline:
desc: Publish the pipeline package
internal: true
cmds:
- task: publish:pipeline:js
# - task: publish:pipeline:python
publish:pipeline:js:
desc: Publish the pipeline package locally
dir: packages/@cdklabs/cdk-cicd-wrapper/dist/js/
internal: true
cmds:
- npm publish
publish:pipeline:python:
desc: Publish the pipeline package locally
dir: packages/@cdklabs/cdk-cicd-wrapper/dist/python/
internal: false
cmds:
- twine upload -r codeartifact *.tar.gz
publish:cli:
desc: Publish the cli package
dir: packages/@cdklabs/cdk-cicd-wrapper-cli/dist/js/
internal: true
cmds:
- npm publish
publish:projen:
desc: Publish the projen package
dir: packages/@cdklabs/cdk-cicd-wrapper-projen/dist/js/
internal: true
cmds:
- npm publish
repository:create:
desc: Create a codeartifact repository
cmds:
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}create-domain --domain {{.DOMAIN}} {{with .AWS_REGION}} --region {{.}} {{end}} &> /dev/null
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}create-repository --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}} &> /dev/null
preconditions:
- sh: 'aws --v'
msg: 'AWS cli is not available. Please install AWS CLI and try again.'
silent: true
status:
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-domain --domain {{.DOMAIN}} {{with .AWS_REGION}} --region {{.}} {{end}}
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-repository --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}}
repository:delete:
desc: Delete a codeartifact repository
cmds:
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}delete-repository --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}} &> /dev/null
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}delete-domain --domain {{.DOMAIN}} {{with .AWS_REGION}} --region {{.}} {{end}} &> /dev/null
silent: true
preconditions:
- sh: 'aws --v'
msg: 'AWS cli is not available. Please install AWS CLI and try again.'
status:
- '[ ! $(aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-domain --domain {{.DOMAIN}} {{with .AWS_REGION}} --region {{.}} {{end}}) ]'
- '[ ! $(aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-repository --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}}) ]'
login:
desc: Login to a codeartifact repository
deps:
- aws:session:active
- repository:create
cmds:
- test -f .npmrc && rm -rf ./.npmrc && echo "[Warning] Project level .npmrc file has been removed." || true
- aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}login --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}} --namespace cdklabs --tool npm
# - aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}login --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}} --tool pip
# - aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}login --domain {{.DOMAIN}} --repository {{.REPOSITORY}} {{with .AWS_REGION}} --region {{.}} {{end}} --tool twine
- task: set-token-secret
silent: true
preconditions:
- sh: 'aws --v'
msg: 'AWS cli is not available. Please install AWS CLI and try again.'
set-token-secret:
desc: Set the token secret for the pipeline
deps:
- create-secret-id
vars:
TOKEN:
sh: aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}get-authorization-token --domain {{.DOMAIN}} --query authorizationToken --output text {{with .AWS_REGION}} --region {{.}} {{end}}
silent: true
cmds:
- >
aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}put-secret-value --secret-id {{.SECRET_ID}} --secret-string \
'{{.TOKEN}}' &> /dev/null
- echo "NPM_REGISTRY=$(aws codeartifact {{with .AWS_PROFILE}} --profile {{.}} {{end}}get-repository-endpoint --domain {{.DOMAIN}} --format npm --output text --repository {{.REPOSITORY}} --output text {{with .AWS_REGION}} --region {{.}} {{end}})" > .env.codeartifact
- echo "NPM_BASIC_AUTH_SECRET_ID=$(aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-secret --secret-id {{.SECRET_ID}} --output text --query ARN)" >> .env.codeartifact
- echo "NPM_SCOPE=cdklabs" >> .env.codeartifact
create-secret-id:
desc: Create the secret id for the pipeline
silent: true
cmds:
- aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}create-secret --name {{.SECRET_ID}} --description "CodeArtifact token for pipeline" &> /dev/null
- echo "Secret id {{.SECRET_ID}} has been created, ARN=$(aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-secret --secret-id {{.SECRET_ID}} --output text --query ARN)."
status:
- aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-secret --secret-id {{.SECRET_ID}}
delete-secret-id:
desc: Delete the secret id for the pipeline
silent: true
cmds:
- aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}delete-secret --force-delete-without-recovery --secret-id {{.SECRET_ID}} &> /dev/null
- echo "Secret id {{.SECRET_ID}} has been deleted."
status:
- '[ ! $(aws secretsmanager {{with .AWS_PROFILE}} --profile {{.}} {{end}}describe-secret --secret-id {{.SECRET_ID}}) ]'
aws:session:active:
internal: true
silent: true
prerequisites:
- sh: 'aws sts {{with .AWS_PROFILE}} --profile {{.}} get-caller-identity'
msg: 'AWS cli is not available. Please install AWS CLI and try again.'
commands:
- aws sts {{with .AWS_PROFILE}} --profile {{.}} get-caller-identity