forked from Backblaze/terraform-provider-b2
-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (178 loc) · 6.84 KB
/
cd.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
176
177
178
179
180
181
182
name: Continuous Delivery
on:
push:
tags: ['v*'] # push events to matching v*, i.e. v1.0, v20.15.10
workflow_dispatch:
inputs:
version_tag:
type: string
description: 'Version tag (in format v1.0.0)'
required: true
default: ''
skip_validate:
type: boolean
description: 'Do not validate a tag with the git commit'
required: true
default: false
publish_as_draft:
type: boolean
description: 'Publish the release as a draft'
required: true
default: false
defaults:
run:
shell: bash
env:
PYTHON_DEFAULT_VERSION: '3.9'
GO_DEFAULT_VERSION: '1.20'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build-pybindings:
runs-on: ${{ matrix.conf.runner }}
strategy:
fail-fast: false
matrix:
conf:
- { runner: ubuntu-latest, os: linux, arch: amd64 }
- { runner: ubuntu-latest, os: linux, arch: arm64 }
- { runner: macos-12, os: darwin, arch: amd64 }
# macos-13-xlarge instance are Apple silicon instances,
# only large and xlarge instances are available as of yet.
- { runner: macos-13, os: darwin, arch: arm64 }
- { runner: windows-2019, os: windows, arch: amd64 }
outputs:
version: ${{ steps.build.outputs.version }}
steps:
- uses: actions/checkout@v2
- name: Start a Docker container (linux)
if: matrix.conf.os == 'linux' && matrix.conf.arch == 'arm64'
run: |
docker run --privileged --rm tonistiigi/binfmt:qemu-v8.0.4 --install arm64
docker run --detach \
--platform linux/arm64 \
--volume .:/work \
--name builder \
arm64v8/python:${{ env.PYTHON_DEFAULT_VERSION }}-bullseye \
/bin/bash -c "sleep infinity"
- name: Start a Docker container (linux-amd64)
if: matrix.conf.os == 'linux' && matrix.conf.arch == 'amd64'
run: |
docker run --detach \
--volume .:/work \
--name builder \
python:${{ env.PYTHON_DEFAULT_VERSION }}-bullseye \
/bin/bash -c "sleep infinity"
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }} (darwin, windows)
if: matrix.conf.os != 'linux'
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Define command wrapper (linux)
if: matrix.conf.os == 'linux'
run: |
# We'll define a 'run' command that will run our commands in the container.
echo '#!/bin/bash' > run
echo 'command="$*"; docker exec --workdir /work/python-bindings builder /bin/bash -c "$command"' >> run
chmod +x run
sudo mv run /usr/local/bin/run
- name: Define command wrapper (darwin)
if: matrix.conf.os == 'darwin'
run: |
# MacOS wrapper just runs commands in python-bindings directory
echo '#!/bin/bash' > run
echo 'pushd python-bindings; "$@"; popd' >> run
chmod +x run
sudo mv run /usr/local/bin/run
- name: Define command wrapper (windows)
if: matrix.conf.os == 'windows'
run: |
# Windows wrapper just runs commands in python-bindings directory
echo '#!/bin/bash' > run
echo 'pushd python-bindings; "$@"; popd' >> run
chmod +x run
mv run /usr/bin/run
- name: Install system dependencies (linux)
if: matrix.conf.os == 'linux'
run: |
run apt update -y
run apt install scons patchelf libnss3-dev -y
- name: Install Python dependencies
run: |
run make deps
- name: Build Python bindings
id: build
run: |
run make build
- if: matrix.conf.os == 'linux'
run: |
sudo chmod -R a+r python-bindings
- name: Upload Python bindings
uses: actions/upload-artifact@v2
with:
name: py-terraform-provider-b2-${{ matrix.conf.os }}-${{ matrix.conf.arch }}
path: python-bindings/dist/py-terraform-provider-b2
if-no-files-found: error
retention-days: 1
build-and-deploy:
needs: [build-pybindings]
env:
NOPYBINDINGS: 1 # do not build python bindings
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
uses: actions/setup-go@v2.1.3
with:
go-version: ${{ env.GO_DEFAULT_VERSION }}
- name: Install dependencies
run: |
make deps
- name: Download python bindings for all OSes
uses: actions/download-artifact@v2
with:
path: python-bindings/dist/artifacts/
- name: Postprocess python bindings
working-directory: python-bindings/dist
run: |
mv artifacts/py-terraform-provider-b2-linux-amd64/py-terraform-provider-b2 py-terraform-provider-b2-linux-amd64
mv artifacts/py-terraform-provider-b2-linux-arm64/py-terraform-provider-b2 py-terraform-provider-b2-linux-arm64
mv artifacts/py-terraform-provider-b2-darwin-amd64/py-terraform-provider-b2 py-terraform-provider-b2-darwin-amd64
mv artifacts/py-terraform-provider-b2-darwin-arm64/py-terraform-provider-b2 py-terraform-provider-b2-darwin-arm64
mv artifacts/py-terraform-provider-b2-windows-amd64/py-terraform-provider-b2 py-terraform-provider-b2-windows-amd64
- name: Set release version output
id: version
run: |
tag=${{ inputs.version_tag != '' && inputs.version_tag || github.ref_name }}
# Strip the prefix 'v'
version=${tag:1}
echo "version=$version" >> $GITHUB_OUTPUT
- name: Read the Changelog
id: read-changelog
uses: mindsers/changelog-reader-action@v2
with:
version: ${{ steps.version.outputs.version }}
- name: Import GPG key
id: import_gpg
uses: paultyng/ghaction-import-gpg@v2.1.0
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
- name: Create GitHub release
uses: goreleaser/goreleaser-action@v6
with:
version: '~> v2'
args: release --clean -p 1 ${{ inputs.skip_validate && '--skip validate' || '' }}
env:
GORELEASER_CURRENT_TAG: v${{ steps.version.outputs.version }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
- name: Update GitHub release
uses: softprops/action-gh-release@v1
with:
name: v${{ steps.version.outputs.version }}
body: ${{ steps.read-changelog.outputs.changes }}
draft: ${{ inputs.publish_as_draft }}
prerelease: false