-
Notifications
You must be signed in to change notification settings - Fork 11
162 lines (158 loc) · 6.05 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
name: Continuous Delivery
on:
push:
tags: ['v*'] # push events to matching v*, i.e. v1.0, v20.15.10
defaults:
run:
shell: bash
env:
PYTHON_DEFAULT_VERSION: '3.13'
GO_DEFAULT_VERSION: '1.22'
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-13, os: darwin, arch: amd64 }
- { runner: macos-14, os: darwin, arch: arm64 }
- { runner: windows-2019, os: windows, arch: amd64 }
outputs:
version: ${{ steps.build.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Start a Docker container (linux-arm64)
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@v5
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@v4
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@v4
with:
fetch-depth: 0
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_DEFAULT_VERSION }}
- name: Install dependencies
run: |
make deps
- name: Download python bindings for all OSes
uses: actions/download-artifact@v4
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=${{ 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: crazy-max/ghaction-import-gpg@v6
with:
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
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
- name: Update GitHub release
uses: softprops/action-gh-release@v2
with:
name: v${{ steps.version.outputs.version }}
body: ${{ steps.read-changelog.outputs.changes }}
draft: false
prerelease: false