-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
122 lines (107 loc) · 4.27 KB
/
action.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
name: 'Testcontainers Cloud'
author: 'AtomicJar'
description: 'Download and setup Testcontainers Cloud Client'
inputs:
version:
description: 'Specific version of Testcontainers Cloud Client to use'
required: false
default: 'latest'
token:
description: 'Testcontainers Cloud API token'
required: false
wait:
description: 'If Testcontainers Cloud Client should wait for a connection before proceeding'
required: false
default: 'false'
args:
description: 'Additional Testcontainers Cloud Client args, not explicitly defined in the action'
required: false
logfile:
description: 'Write Testcontainers Cloud Client output into specified logfile'
required: false
action:
description: 'What should be done exactly: prepare|terminate'
required: false
default: prepare
project-key:
description: 'Project identifier'
required: false
project-url:
description: 'Project URL'
required: false
runs:
using: 'composite'
steps:
- id: testcontainers-cloud-env-vars
name: Preparing Testcontainers Cloud env vars
shell: bash
run: |
# prepare tcc env vars
projectKey="$GITHUB_REPOSITORY"
if [[ ! -z "$INPUT_PROJECT_KEY" ]]; then
projectKey="$INPUT_PROJECT_KEY"
elif [[ ! -z "$TCC_PROJECT_KEY" ]]; then
projectKey="$TCC_PROJECT_KEY"
fi
projectUrl="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
if [[ ! -z "$INPUT_PROJECT_URL" ]]; then
projectUrl="$INPUT_PROJECT_URL"
elif [[ ! -z "$TCC_PROJECT_URL" ]]; then
projectUrl="$TCC_PROJECT_URL"
fi
echo "TCC_PROJECT_KEY=${projectKey}" >> $GITHUB_ENV
echo "TCC_PROJECT_URL=${projectUrl}" >> $GITHUB_ENV
env:
INPUT_PROJECT_KEY: ${{ inputs.project-key }}
INPUT_PROJECT_URL: ${{ inputs.project-url }}
- id: testcontainers-cloud
name: Download and run Testcontainers Cloud Client
shell: bash
env:
TC_CLOUD_TOKEN: ${{ inputs.token || env.TC_CLOUD_TOKEN }}
TC_CLOUD_LOGS_ENABLE_COLORS: 'true'
TCC_BINARY_NAME: ${{ env.TCC_BINARY_NAME || 'tcc-agent' }}
if: inputs.action == 'prepare'
run: |
# download and run the agent at the background
# determine the architecture of the platform
suffix=$([[ $(uname -m) == "aarch64" || $(uname -m) == "arm64" ]] && echo "arm64" || echo "x86-64")
# determine the os for the agent
os=$([[ $RUNNER_OS == "macOS" ]] && echo "darwin" || echo $([[ $RUNNER_OS == "Windows" ]] && echo "windows" || echo "linux"))
# determine the extension of the package
extension=$([[ $os == "windows" ]] && echo ".exe" || echo "")
VERSION=${{ inputs.version }}
TCC_AGENT_ARGS="${{ inputs.args }} --terminate"
LATEST_BINARY_URL="https://app.testcontainers.cloud/download/testcontainers-cloud-agent_${VERSION}_${os}_${suffix}${extension}"
TCC_LOGFILE="${{ inputs.logfile }}"
# fetch the latest TCC agent version and make it executable
echo "Downloading ${LATEST_BINARY_URL}"
curl -fsSL -o "${TCC_BINARY_NAME}" "${LATEST_BINARY_URL}"
chmod +x ${TCC_BINARY_NAME}
# start agent as background process
if [ $TCC_LOGFILE ]
then
TC_CLOUD_LOGS_ENABLE_COLORS=false ./"${TCC_BINARY_NAME}" ${TCC_AGENT_ARGS} > "${TCC_LOGFILE}" 2>&1 &
else
./"${TCC_BINARY_NAME}" ${TCC_AGENT_ARGS} &
fi
- id: testcontainers-cloud-client-wait
name: Make sure TCC is ready before proceeding
shell: bash
if: inputs.wait == 'true' && inputs.action == 'prepare'
env:
TC_CLOUD_LOGS_ENABLE_COLORS: 'true'
TCC_BINARY_NAME: ${{ env.TCC_BINARY_NAME || 'tcc-agent' }}
run: |
# waiting for agent successful connection
./"${TCC_BINARY_NAME}" wait
- id: testcontainers-cloud-client-terminate
name: Make sure TCC is ready before proceeding
shell: bash
if: inputs.action == 'terminate'
env:
TC_CLOUD_LOGS_ENABLE_COLORS: 'true'
TCC_BINARY_NAME: ${{ env.TCC_BINARY_NAME || 'tcc-agent' }}
run: |
# Terminating active sessions
./"${TCC_BINARY_NAME}" terminate