-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (153 loc) · 7.38 KB
/
builder.yml
File metadata and controls
170 lines (153 loc) · 7.38 KB
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
name: 'Builder'
on:
workflow_call:
inputs:
branch-name:
description: 'Name of the branch where the workflow was triggered'
required: true
default: ''
type: string
branch-ref:
description: 'Reference of the branch where the workflow was triggered'
required: true
default: ''
type: string
update-major-version:
description: 'Update major version'
required: false
default: false
type: boolean
update-minor-version:
description: 'Update minor version'
required: false
default: false
type: boolean
update-patch-version:
description: 'Update patch version'
required: false
default: false
type: boolean
pre-release-type:
description: 'Pre-release type (only `alpha`, `release-candidate` or `` are allowed)'
required: false
default: 'NaN'
type: string
outputs:
release:
description: 'The current release version (e.g. `x.y`)'
value: '${{ jobs.build_upload_artifacts.outputs.release }}'
version:
description: 'The current build version (e.g. `x.y.z(-(alpha|release-candidate)-(epoch))?`)'
value: '${{ jobs.build_upload_artifacts.outputs.version }}'
pre-release-type:
description: 'The current pre-release type (if defined) (e.g. `alpha`, `release-candidate`, ``)'
value: '${{ jobs.build_upload_artifacts.outputs.pre-release-type }}'
pre-release-metadata:
description: 'The current pre-release metadata (if defined) (e.g. `alpha-1692107243`, `release-candidate-1692112160`, ``)'
value: '${{ jobs.build_upload_artifacts.outputs.pre-release-metadata }}'
jobs:
# Build and upload artifacts
build_upload_artifacts:
outputs:
release: '${{ steps.versioning.outputs.release }}'
version: '${{ steps.versioning.outputs.version }}'
pre-release-type: '${{ steps.versioning.outputs.pre-release-type }}'
pre-release-metadata: '${{ steps.versioning.outputs.pre-release-metadata }}'
runs-on: ubuntu-latest
# Set GITHUB_TOKEN required permissions
permissions:
contents: write
actions: write
packages: write
steps:
- name: 'Set up steps'
id: setup
run: |
echo "repository=$( echo "${{ github.repository }}" )" >> $GITHUB_OUTPUT
echo "repository_owner=$( echo "${{ github.repository_owner }}" )" >> $GITHUB_OUTPUT
echo "repository_name=$( echo "${{ github.event.repository.name }}" )" >> $GITHUB_OUTPUT
echo "branch_name=$( echo "${{ inputs.branch-name }}" )" >> $GITHUB_OUTPUT
echo "branch_ref=$( echo "${{ inputs.branch-ref }}" )" >> $GITHUB_OUTPUT
echo "update_major_version=$( echo "${{ inputs.update-major-version }}" )" >> $GITHUB_OUTPUT
echo "update_minor_version=$( echo "${{ inputs.update-minor-version }}" )" >> $GITHUB_OUTPUT
echo "update_patch_version=$( echo "${{ inputs.update-patch-version }}" )" >> $GITHUB_OUTPUT
echo "pre_release_type=$( echo "${{ inputs.pre-release-type }}" )" >> $GITHUB_OUTPUT
echo "pre_release_metadata=$( if [[ ("${{ inputs.pre-release-type }}" == "NaN") ]]; then echo "NaN"; elif [[ ("${{ inputs.pre-release-type }}" == "") ]]; then echo ""; else echo "${{ inputs.pre-release-type }}-$( date +%s )"; fi )" >> $GITHUB_OUTPUT
shell: bash
- name: 'Check out repository'
id: checkout
uses: actions/checkout@v3
with:
ref: '${{ steps.setup.outputs.branch_ref }}'
- name: Determine environment
id: determine_environment
run: |
if [ "${{ github.ref_name }}" = "master" ]; then
echo "::set-output name=environment::prod"
else
echo "::set-output name=environment::${{ github.ref_name }}"
fi
- name: 'Bump build version'
id: bump-build-version
if: ${{ (inputs.update-major-version == 'true') || (inputs.update-minor-version == 'true') || (inputs.update-patch-version == 'true') || (inputs.pre-release-type != 'NaN') }}
uses: valispace/actions/bump-build-version@master
with:
versioning-file: 'backend/valifn/__init__.py'
update-major-version: ${{ steps.setup.outputs.update_major_version }}
update-minor-version: ${{ steps.setup.outputs.update_minor_version }}
update-patch-version: ${{ steps.setup.outputs.update_patch_version }}
pre-release-metadata: '${{ steps.setup.outputs.pre_release_metadata }}'
- name: 'Get build version'
id: versioning
uses: valispace/actions/get-build-version@master
with:
versioning-file: 'backend/valifn/__init__.py'
- name: 'Commit changes'
id: commit-changes
if: ${{ (inputs.update-major-version == 'true') || (inputs.update-minor-version == 'true') || (inputs.update-patch-version == 'true') || (inputs.pre-release-type != 'NaN') }}
uses: valispace/actions/commit-changes@master
with:
protected-branch-token: '${{ secrets.REPO_ADMIN_TOKEN }}'
repository-owner: '${{ steps.setup.outputs.repository_owner }}'
repository-name: '${{ steps.setup.outputs.repository_name }}'
branch-name: '${{ steps.setup.outputs.branch_name }}'
commit-author: 'github_actions'
commit-message: 'feat(release): build ${{ steps.versioning.outputs.version }}'
- name: 'Build and push docker image to AWS ECR'
id: aws-build-push-image
uses: valispace/actions/aws-build-push-image@master
with:
aws-secret-access-key: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
aws-access-key-id: '${{ secrets.AWS_ACCESS_KEY_ID }}'
aws-ecr-repository: '${{ github.event.repository.name }}'
aws-s3-bucket: '${{ secrets.S3_BUCKET }}'
aws-s3-repository: '${{ github.event.repository.name }}'
aws-s3-branch: '${{ github.ref_name }}'
dockerfile-path: 'docker/backend/Dockerfile'
version: '${{ steps.versioning.outputs.version }}'
environment: '${{ steps.determine_environment.outputs.environment }}'
archive-name: '${{ github.event.repository.name }}-docker'
- name: 'Build docker image'
id: docker-build-image
if: ${{ (steps.setup.outputs.branch_name == 'master') }}
uses: valispace/actions/docker-build-image@master
with:
dockerfile: 'docker/backend/Dockerfile'
archive-name: '${{ steps.setup.outputs.repository_name }}-docker.tar.gz'
labels: 'version=${{ steps.versioning.outputs.version }}'
tags: |
${{ steps.setup.outputs.repository }}:${{ steps.versioning.outputs.version }}
${{ steps.setup.outputs.repository }}:latest
- name: 'Push docker image to Docker Hub'
id: docker-push-image
if: ${{ (steps.setup.outputs.branch_name == 'master') }}
uses: valispace/actions/docker-push-image@master
with:
dockerfile: 'docker/backend/Dockerfile'
registry: ''
username: '${{ secrets.DOCKERHUB_USERNAME }}'
password: '${{ secrets.DOCKERHUB_TOKEN }}'
labels: 'version=${{ steps.versioning.outputs.version }}'
tags: |
${{ steps.setup.outputs.repository }}:${{ steps.versioning.outputs.version }}
${{ steps.setup.outputs.repository }}:latest