-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
117 lines (117 loc) · 4.99 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
name: Asset Push
description: This is a GitHub Action designed to push built assets required by Nullplatform
inputs:
build-id:
description: The type of asset to be pushed. One of docker-image, lambda, etc.
required: true
type:
description: The type of asset to be pushed. One of docker-image, lambda, etc.
required: true
build-working-directory:
description: The directory where the build process will take place
required: false
default: .
asset-working-directory:
description: The directory containing source code and assets for the build process
required: false
default: .
asset-output-directory:
description: The directory where built assets will be output
required: false
default: build
name:
description: The name of the asset being pushed
required: false
default: main
url:
description: Predefined asset URL. This is an advanced usage and is not recommended, use *type* and *name* instead
required: false
api-key:
description: The API key required for authentication if not logged in
required: false
runs:
using: composite
steps:
- if: ${{ !env.NULLPLATFORM_ACCESS_TOKEN }}
name: Log into nullplatform
id: login
uses: nullplatform/github-action-login@v1
with:
api-key: ${{ inputs.api-key }}
- name: Sanitize Paths
id: sanitize-paths
shell: bash
run: |
# Sanitize function
sanitize_path() {
local path="$1"
# Remove "./" from the beginning of the path, but preserve "."
if [ "$path" != "./" ]; then
path="${path#./}"
fi
# Remove trailing slashes
path="${path%/}"
echo "$path"
}
# Sanitize paths
build_working_directory=$(sanitize_path "${{ inputs.build-working-directory }}")
asset_working_directory=$(sanitize_path "${{ inputs.asset-working-directory }}")
asset_output_directory=$(sanitize_path "${{ inputs.asset-output-directory }}")
# Export sanitized paths
echo "build-working-directory=$build_working_directory" >> "$GITHUB_OUTPUT"
echo "asset-working-directory=$asset_working_directory" >> "$GITHUB_OUTPUT"
echo "asset-output-directory=$asset_output_directory" >> "$GITHUB_OUTPUT"
- name: Create asset for build
id: create-asset
uses: nullplatform/github-action-asset@v1
with:
action: create
build-id: ${{ inputs.build-id }}
type: ${{ inputs.type }}
name: ${{ inputs.name }}
url: ${{ inputs.url }}
- name: Save asset repository provider into context
id: save-asset-repository-provider
shell: bash
run: echo "ASSET_REPOSITORY_PROVIDER=${{ fromJson(steps.create-asset.outputs.targets)[0].provider }}" >> $GITHUB_ENV
- if: ${{ contains(fromJSON('["aws-ecr", "aws-s3"]'), env.ASSET_REPOSITORY_PROVIDER) }}
name: Setup AWS Asset Repository Provider
id: ci-setup-aws-repository-provider
uses: nullplatform/github-action-asset-push/aws-asset-repository-provider@v1
with:
type: ${{ inputs.type }}
- if: ${{ env.ASSET_REPOSITORY_PROVIDER == 'azure-container-registry' }}
name: Setup Azure Asset Repository Provider
id: ci-setup-azure-repository-provider
uses: nullplatform/github-action-asset-push/azure-asset-repository-provider@v1
with:
type: ${{ inputs.type }}
- name: Push asset
id: push-asset
shell: bash
env:
BUILD_WORKING_DIRECTORY: ${{ steps.sanitize-paths.outputs.build-working-directory }}
ASSET_WORKING_DIRECTORY: ${{ steps.sanitize-paths.outputs.asset-working-directory }}
ASSET_OUTPUT_DIRECTORY: ${{ steps.sanitize-paths.outputs.asset-working-directory }}/${{ steps.sanitize-paths.outputs.asset-output-directory }}
ASSET_NAME: ${{ inputs.name }}
ASSET_TYPE: ${{ inputs.type }}
ASSET_TARGET_URL: ${{ fromJson(steps.create-asset.outputs.targets)[0].url }}
run: |
make_file_path="${{ steps.sanitize-paths.outputs.build-working-directory }}"
make_file_task="push"
if [ ! -f "$make_file_path/makefile" ] && [ ! -f "$make_file_path/Makefile" ]; then
echo "Makefile not found in the '${{ steps.sanitize-paths.outputs.build-working-directory }}' folder. Using defaults."
make_file_path="${{ github.action_path }}"
make_file_task="push-${{ inputs.type }}"
# Override directories to work with default Makefile
BUILD_WORKING_DIRECTORY=$(realpath "$BUILD_WORKING_DIRECTORY")
ASSET_WORKING_DIRECTORY=$(realpath "$ASSET_WORKING_DIRECTORY")
ASSET_OUTPUT_DIRECTORY=$(realpath "$ASSET_OUTPUT_DIRECTORY")
fi
make -C $make_file_path $make_file_task \
BUILD_WORKING_DIRECTORY=$BUILD_WORKING_DIRECTORY \
ASSET_WORKING_DIRECTORY=$ASSET_WORKING_DIRECTORY \
ASSET_OUTPUT_DIRECTORY=$ASSET_OUTPUT_DIRECTORY \
ASSET_NAME=$ASSET_NAME \
ASSET_TYPE=$ASSET_TYPE \
ASSET_TARGET_URL=$ASSET_TARGET_URL