Skip to content

Commit

Permalink
releng - windows support - ci and wheel building (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilt authored Jan 10, 2024
1 parent 5e59649 commit e2380c3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ jobs:
name: wheels-linux-${{ matrix.cibw_arch }}
path: ./wheelhouse/*.whl

Build-Windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: "1.21.5"
cache: true
cache-dependency-path: "gotfparse/go.sum"
- name: Build wheels
uses: pypa/cibuildwheel@fff9ec32ed25a9c576750c91e06b410ed0c15db7
env:
CGO_ENABLED: 1
CIBW_ARCHS: AMD64
- name: Upload Artifacts
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392
with:
name: wheels-windows
path: ./wheelhouse/*.whl

Build-MacOS:
strategy:
matrix:
Expand Down Expand Up @@ -69,7 +91,7 @@ jobs:
path: ./wheelhouse/*.whl

Gather:
needs: [Build-Linux, Build-MacOS]
needs: [Build-Linux, Build-MacOS, Build-Windows]
runs-on: ubuntu-latest
outputs:
hash: ${{ steps.hash.outputs.hash }}
Expand Down
29 changes: 22 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # ratchet:actions/checkout@v2
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # ratchet:actions/setup-python@v4
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c
with:
python-version: "3.11"
- name: Install dependencies
Expand All @@ -29,18 +30,32 @@ jobs:
flake8 tfparse tests
Tests:
needs: Lint
runs-on: ubuntu-latest
runs-on: ${{ matrix.runner }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
runner: ["ubuntu-latest", "windows-latest", "macos-latest"]
exclude:
# just conserving runners by excluding older versions
- runner: macos-latest
python-version: 3.10
- runner: windows-latest
python-version: 3.10
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # ratchet:actions/checkout@v2
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # ratchet:actions/setup-python@v4
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c
with:
python-version: ${{ matrix.python-version }}

- name: Set up Terraform
uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_wrapper: false

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # ratchet:actions/setup-go@v3
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: "1.21.5"
cache: true
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ from defsec to offer a high level interface to parsing terraform modules.
pip install tfparse
```

We currently distribute binaries for MacOS (x86_64, arm64) and Linux (x86_64, aarch64).
We currently distribute binaries for MacOS (x86_64, arm64) and Linux (x86_64, aarch64) and Windows.

Note on Windows we currently don't free memory allocated on parse results.

# Usage

Expand Down
6 changes: 5 additions & 1 deletion tests/test_tfparse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path
import shutil
import sys
from pathlib import Path
from unittest.mock import ANY

Expand Down Expand Up @@ -36,7 +37,10 @@ def test_parse_no_dir(tmp_path):
with pytest.raises(ParseError) as e_info:
load_from_path(tmp_path / "xyz")

assert "no such file or directory" in str(e_info)
if sys.platform == "win32":
assert "The system cannot find the file specified" in str(e_info)
else:
assert "no such file or directory" in str(e_info)


def test_vars(tmp_path):
Expand Down
7 changes: 5 additions & 2 deletions tfparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
import json
import sys
import sysconfig
import typing as tp
from pathlib import Path
Expand Down Expand Up @@ -48,10 +49,12 @@ def load_from_path(

if ret.err != ffi.NULL:
err = ffi.string(ret.err)
ffi.gc(ret.err, lib.free)
if sys.platform != "win32":
ffi.gc(ret.err, lib.free)
err = err.decode("utf8")
raise ParseError(err)

ret_json = ffi.string(ret.json)
ffi.gc(ret.json, lib.free)
if sys.platform != "win32":
ffi.gc(ret.json, lib.free)
return json.loads(ret_json)

0 comments on commit e2380c3

Please sign in to comment.