Skip to content

Commit

Permalink
Merge branch 'master' into expand-endpoint-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
metadaddy authored Sep 10, 2024
2 parents 0d04997 + 42733c1 commit 78b32e4
Show file tree
Hide file tree
Showing 26 changed files with 464 additions and 448 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Continuous Delivery

on:
push:
tags: 'v*' # push events to matching v*, i.e. v1.0, v20.15.10
tags: ['v*'] # push events to matching v*, i.e. v1.0, v20.15.10

defaults:
run:
shell: bash

env:
PYTHON_DEFAULT_VERSION: '3.9'
GO_DEFAULT_VERSION: '1.20'
PYTHON_DEFAULT_VERSION: '3.12'
GO_DEFAULT_VERSION: '1.22'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
Expand All @@ -28,8 +28,8 @@ jobs:
outputs:
version: ${{ steps.build.outputs.version }}
steps:
- uses: actions/checkout@v2
- name: Start a Docker container (linux)
- 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
Expand All @@ -49,7 +49,7 @@ jobs:
/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
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Define command wrapper (linux)
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
run: |
sudo chmod -R a+r python-bindings
- name: Upload Python bindings
uses: actions/upload-artifact@v2
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
Expand All @@ -106,18 +106,18 @@ jobs:
outputs:
upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
uses: actions/setup-go@v2.1.3
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@v2
uses: actions/download-artifact@v4
with:
path: python-bindings/dist/artifacts/
- name: Postprocess python bindings
Expand All @@ -142,7 +142,7 @@ jobs:
version: ${{ steps.version.outputs.version }}
- name: Import GPG key
id: import_gpg
uses: paultyng/ghaction-import-gpg@v2.1.0
uses: paultyng/ghaction-import-gpg@v2
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
Expand All @@ -154,7 +154,7 @@ jobs:
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
- name: Update GitHub release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
name: v${{ steps.version.outputs.version }}
body: ${{ steps.read-changelog.outputs.changes }}
Expand Down
79 changes: 38 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ on:
push:
branches: [master]
paths-ignore:
- '.github/no-response.yml'
- '.github/workflows/cd.yml'
- 'LICENSE'
- 'README.md'
- 'README.release.md'
pull_request:
branches: [master]

Expand All @@ -13,20 +17,20 @@ defaults:
shell: bash

env:
PYTHON_DEFAULT_VERSION: '3.9'
GO_DEFAULT_VERSION: '1.20'
PYTHON_DEFAULT_VERSION: '3.12'
GO_DEFAULT_VERSION: '1.22'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v2
uses: deadsnakes/[email protected] # staticx doesn't work with python installed by setup-python action
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
uses: actions/setup-go@v2.1.3
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_DEFAULT_VERSION }}
- name: Install dependencies
Expand All @@ -44,34 +48,34 @@ jobs:
- name: Validate changelog
# Library was designed to be used with pull requests only.
if: ${{ github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: zattoo/changelog@v1
uses: zattoo/changelog@v2
with:
token: ${{ github.token }}
build:
needs: lint
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.conf.runner }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-12 # amd64
- macos-14 # arm64
- windows-2019
conf:
- { runner: ubuntu-latest, os: linux, arch: amd64 }
- { runner: macos-12, os: darwin, arch: amd64 }
- { runner: macos-14, os: darwin, arch: arm64 }
- { runner: windows-2019, os: windows, arch: amd64 }
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }} (ubuntu-latest)
if: matrix.os == 'ubuntu-latest'
uses: deadsnakes/action@v2.1.1
if: matrix.conf.os == 'linux'
uses: deadsnakes/action@v3.1.0 # staticx doesn't work with python installed by setup-python action
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
if: matrix.os != 'ubuntu-latest'
uses: actions/setup-python@v2
if: matrix.conf.os != 'linux'
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
uses: actions/setup-go@v2.1.3
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_DEFAULT_VERSION }}
- name: Install dependencies
Expand All @@ -81,7 +85,7 @@ jobs:
run: |
make build
- name: Upload python bindings
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: py-terraform-provider-b2-${{ runner.os }}-${{ runner.arch }}
path: python-bindings/dist/py-terraform-provider-b2
Expand All @@ -93,40 +97,33 @@ jobs:
B2_TEST_APPLICATION_KEY: ${{ secrets.B2_TEST_APPLICATION_KEY }}
B2_TEST_APPLICATION_KEY_ID: ${{ secrets.B2_TEST_APPLICATION_KEY_ID }}
NOPYBINDINGS: 1 # do not build python buildings
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.conf.runner }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-12 # amd64
- macos-14 # arm64
- windows-2019
terraform:
- '1.5.*'
- '1.4.*'
exclude:
- os: macos-12 # for macOS, the latest terraform is enough for ACC tests
terraform: '1.4.*'
- os: macos-14 # for macOS, the latest terraform is enough for ACC tests
terraform: '1.4.*'
- os: windows-2019 # for Windows, the latest terraform is enough for ACC tests
terraform: '1.4.*'
conf:
- { runner: ubuntu-latest, os: linux, arch: amd64, terraform: '1.9.*' }
- { runner: ubuntu-latest, os: linux, arch: amd64, terraform: '1.8.*' }
# for macOS, the latest terraform is enough for ACC tests
- { runner: macos-12, os: darwin, arch: amd64, terraform: '1.9.*' }
- { runner: macos-14, os: darwin, arch: arm64, terraform: '1.9.*' }
# for Windows, the latest terraform is enough for ACC tests
- { runner: windows-2019, os: windows, arch: amd64, terraform: '1.9.*' }
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }}
uses: actions/setup-go@v2.1.3
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_DEFAULT_VERSION }}
- uses: hashicorp/setup-terraform@v2
name: Set up Terraform ${{ matrix.terraform }}
- uses: hashicorp/setup-terraform@v3
name: Set up Terraform ${{ matrix.conf.terraform }}
with:
terraform_version: ${{ matrix.terraform }}
terraform_version: ${{ matrix.conf.terraform }}
terraform_wrapper: false
- name: Download python bindings for given OS
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }}
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: py-terraform-provider-b2-${{ runner.os }}-${{ runner.arch }}
path: python-bindings/dist/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pkged.go
*.pyc
*.egg-info
.python-version
b2/py-terraform-provider-b2
build/
dist/
venv/
5 changes: 2 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ builds:
goarch: arm64
hooks:
pre:
- cp python-bindings/dist/py-terraform-provider-b2-{{ .Os }}-{{ .Arch }} python-bindings/dist/py-terraform-provider-b2
- pkger -include /python-bindings/dist/py-terraform-provider-b2
- cp python-bindings/dist/py-terraform-provider-b2-{{ .Os }}-{{ .Arch }} b2/py-terraform-provider-b2
post:
- rm -f python-bindings/dist/py-terraform-provider-b2
- rm -f b2/py-terraform-provider-b2
env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Infrastructure
* Replace removed macOS 11 Big Sur in favour of macOS 12 Monterey in CI/CD
* Add support for Windows
* Use Python 3.12 for embedded pybindings
* Use Go 1.22

### Fixed
* Fixed `allowed_operations` stability issue
Expand Down
19 changes: 11 additions & 8 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ endif

deps: _pybindings
@go mod download
@go install github.com/markbates/pkger/cmd/pkger
@go mod tidy
@cd tools && go mod download
@cd tools && go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
Expand All @@ -28,7 +27,7 @@ deps-check:
@go mod tidy
@cd tools && go mod tidy
@git diff --exit-code -- go.mod go.sum tools/go.mod tools/go.sum || \
(echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1)
(echo; echo "Unexpected difference in go.mod/go.sum files. Run 'make deps' command or revert any go.mod/go.sum changes and commit."; exit 1)

format: _pybindings
@go fmt ./...
Expand All @@ -39,24 +38,28 @@ lint: _pybindings
@python scripts/check-headers.py '**/*.go' pkged.go

testacc: _pybindings
@chmod +rx python-bindings/dist/py-terraform-provider-b2
@cp python-bindings/dist/py-terraform-provider-b2 b2/
@chmod +rx b2/py-terraform-provider-b2
TF_ACC=1 go test ./${NAME} -v -count 1 -parallel 4 -timeout 120m $(TESTARGS)

clean: _pybindings
@rm -rf dist pkged.go ${BINARY}
@rm -rf dist b2/py-terraform-provider-b2 ${BINARY}

build: _pybindings
@pkger -include /python-bindings/dist/py-terraform-provider-b2
go build -tags netgo -o ${BINARY}
@cp python-bindings/dist/py-terraform-provider-b2 b2/
@go build -tags netgo -o ${BINARY}

install: build
@mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
@mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

docs: build
@tfplugindocs

docs-lint:
docs-lint: build
@tfplugindocs validate
@tfplugindocs
@git diff --exit-code -- docs/ || \
(echo; echo "Unexpected difference in docs. Run 'make docs' command or revert any changes in the schema."; exit 1)

all: deps lint build testacc
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ The provider is written in go, but it uses official [B2 python SDK](https://gith
Requirements
------------

Runtime requirements:
- [Terraform](https://www.terraform.io/downloads.html) >= 1.0.0
- [Go](https://golang.org/doc/install) >= 1.20
- [Python](https://github.com/pyenv/pyenv) >= 3.9

Development requirements:
- [Go](https://golang.org/doc/install) == 1.22
- [Python](https://github.com/pyenv/pyenv) == 3.12

Dependencies
------------
Expand Down
24 changes: 8 additions & 16 deletions b2/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package b2

import (
"bufio"
"github.com/markbates/pkger"
"embed"
"io"
"io/ioutil"
"log"
Expand All @@ -24,10 +24,12 @@ import (

var (
bindings *string
lock = &sync.Mutex{}
//go:embed py-terraform-provider-b2
content embed.FS
lock = &sync.Mutex{}
)

func GetBindings(sourcePath string, testing bool) (string, error) {
func GetBindings() (string, error) {
if bindings == nil {
lock.Lock()
defer lock.Unlock()
Expand All @@ -36,19 +38,9 @@ func GetBindings(sourcePath string, testing bool) (string, error) {
return *bindings, nil
}

var sourceFile io.ReadCloser
if testing == true {
src, err := os.Open(sourcePath)
if err != nil {
return "", err
}
sourceFile = src
} else {
src, err := pkger.Open(sourcePath)
if err != nil {
return "", err
}
sourceFile = src
sourceFile, err := content.Open("py-terraform-provider-b2")
if err != nil {
return "", err
}
defer sourceFile.Close()

Expand Down
Loading

0 comments on commit 78b32e4

Please sign in to comment.