-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
126 lines (124 loc) · 6.2 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
123
124
125
126
name: 'Speckle Automate Function - Build and Publish'
description: 'Builds and publishes a new version of a Speckle Automate Function to the Speckle Automate platform.'
author: 'specklesystems'
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
speckle_automate_url:
description: 'Speckle Automate URL. Should include the `https://` protocol and not end with a trailing slash.'
required: false
default: 'https://automate.speckle.dev' #TODO change to https://automate.speckle.systems
speckle_token:
description: 'Token for authentication to Speckle Automate Server, allowing publishing of Speckle Functions. **The token must be stored in GitHub as an encrypted secret**.'
required: true
speckle_function_id:
description: 'The unique identifier of the function. Go to Speckle Automate to register your Function and get its Identifier.'
required: true
speckle_function_input_schema_file_path:
description: 'File path containing JSON Schema of the parameters object required by the function. These will be used to create the User Interface displayed to users of your Function in Speckle Automate. Users will be able to provide their data to customise the Function.'
required: false
speckle_function_command:
description: 'The command to run to execute the function in a runtime environment.'
required: true
speckle_function_recommended_cpu_m:
description: 'The recommended maximum CPU in millicores for the function. 1000 millicores = 1 CPU core. Defaults to 1000 millicores (1 CPU core). If the Function exceeds this limit, it will be throttled to run within the limit.'
required: false
speckle_function_recommended_memory_mi:
description: 'The recommended maximum memory in mebibytes for the function. 1024 mebibytes = 1 gibibyte. Defaults to 100 mebibytes. If the Function exceeds this limit, it will be terminated.'
required: false
dockerfile_path:
description: 'Path to the Dockerfile to be used to build the Speckle Function.'
required: false
default: './Dockerfile'
docker_context:
description: 'Path to the directory containing the build context for the Docker image.'
required: false
default: '.' # root directory of the checked out source code
runs:
using: "composite"
steps:
- uses: actions/checkout@v4 # checkout the repository in which this GitHub Action is being used.
- name: Validate inputs
shell: bash
run: |
if [ -z "${{ inputs.speckle_token }}" ]; then
echo "ERROR: speckle_token secret is required"
exit 1
fi
if [ -z "${{ inputs.speckle_automate_url }}" ]; then
echo "ERROR: speckle_automate_url input value is required"
exit 1
fi
if [ -z "${{ inputs.speckle_function_id }}" ]; then
echo "ERROR: speckle_function_id input value is required"
exit 1
fi
if [ -z "${{ inputs.speckle_function_input_schema_file_path }}" ]; then
echo "ERROR: speckle_function_input_schema_file_path input value is required"
exit 1
fi
if [ -z "${{ inputs.speckle_function_command }}" ]; then
echo "ERROR: speckle_function_command input value is required"
exit 1
fi
- name: Set Version tag
shell: bash
run: |
echo "Determining Release tag value"
if [[ ${GITHUB_REF_TYPE} == "tag" ]]
then
echo "Workflow triggered by a git tag"
RELEASE_TAG=${GITHUB_REF_NAME}
else
echo "Workflow triggered on a git branch"
RELEASE_TAG=$(git rev-parse --short ${GITHUB_SHA})
fi
echo "Setting the function's releaseTag to: ${RELEASE_TAG}"
echo "releaseTag=${RELEASE_TAG}" >> "$GITHUB_ENV"
- name: Set up Docker Buildx # required to enable caching of docker build
uses: docker/setup-buildx-action@v3
- name: Log in to Speckle Automate Docker registry
uses: docker/[email protected]
with:
registry: ${{ inputs.speckle_automate_url }}
username: ${{ inputs.speckle_token }}
password: ${{ inputs.speckle_token }}
- name: Parse automate host
shell: bash
run: |
AUTOMATE_HOST=$(python -c 'from urllib.parse import urlparse; print(urlparse("${{ inputs.speckle_automate_url }}").netloc)')
echo "Parsed automate host: ${AUTOMATE_HOST}"
echo "automateHost=${AUTOMATE_HOST}" >>"$GITHUB_ENV"
- name: Ensure image doesn't exist in registry
shell: bash
run: |
set +e
docker manifest inspect ${{ env.automateHost }}/${{ inputs.speckle_function_id }}:${{ env.releaseTag }}
if [[ $? == 0 ]]
then
echo "Cannot override the existing release tag ${{ env.releaseTag }}. Please publish a new release!"
exit 1
fi
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: ${{ inputs.docker_context }}
file: ${{ inputs.dockerfile_path }}
tags: ${{ env.automateHost }}/${{ inputs.speckle_function_id }}:${{ env.releaseTag }}
target: ''
push: true
cache-from: type=registry,ref=${{ env.automateHost }}/${{ inputs.speckle_function_id }}:buildcache
cache-to: type=registry,ref=${{ env.automateHost }}/${{ inputs.speckle_function_id }}:buildcache,mode=max
- name: Speckle Automate function version publisher
uses: specklesystems/[email protected]
id: register_speckle_function_version
with:
speckle_automate_url: ${{ inputs.speckle_automate_url }}
speckle_token: ${{ inputs.speckle_token }}
speckle_function_id: ${{ inputs.speckle_function_id }}
speckle_function_input_schema_file_path: ${{ inputs.speckle_function_input_schema_file_path }}
speckle_function_release_tag: ${{ env.releaseTag }}
speckle_function_command: ${{ inputs.speckle_function_command }}
speckle_function_recommended_cpu_m: ${{ inputs.speckle_function_recommended_cpu_m }}
speckle_function_recommended_memory_mi: ${{ inputs.speckle_function_recommended_memory_mi }}