Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tdewolff/minify
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 26, 2023
2 parents 1d7174f + 019c305 commit 2281e8e
Show file tree
Hide file tree
Showing 17 changed files with 429 additions and 200 deletions.
8 changes: 8 additions & 0 deletions .ci/ensure-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if command -v dnf; then
dnf -y install golang gcc
elif command -v yum; then
yum install epel-release
yum -y install golang gcc
elif command -v apk; then
apk add go gcc
fi
10 changes: 5 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: docker/metadata-action@v4
- uses: docker/metadata-action@v5
id: meta
with:
images: tdewolff/minify

- uses: docker/login-action@v2
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- uses: docker/setup-buildx-action@v2
- uses: docker/setup-buildx-action@v3

- uses: docker/build-push-action@v4
- uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
Expand All @@ -37,7 +37,7 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
248 changes: 248 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
name: Python

on:
push:
tags:
- 'v*'

permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- go_target: amd64
cibw_target: x86_64
#- go_target:'386
# cibw_target: i686
- go_target: arm64
cibw_target: aarch64

steps:
- uses: actions/checkout@v3

- name: Set up QEMU
if: matrix.go_target == 'arm64'
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Build wheels
uses: pypa/[email protected]
with:
package-dir: bindings/py
env:
CIBW_ARCHS: ${{ matrix.cibw_target }}
CIBW_MANYLINUX_I686_IMAGE: quay.io/pypa/manylinux_2_28_i686
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64
CIBW_BEFORE_ALL: .ci/ensure-go.sh; cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so

- name: Upload to GitHub Release
uses: softprops/[email protected]
if: startsWith(github.ref, 'refs/tags/')
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-linux-${{ matrix.go_target }}
path: ./wheelhouse/*.whl

windows-go-crosscompile:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- go_target: amd64
xcompiler: x86_64-w64-mingw32-gcc-win32
# go_target: 386
# xcompiler: i686-w64-mingw32-gcc-win32

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-go@v4
with:
go-version: '>=1.17'
- name: Fetch go package
if: startsWith(github.ref, 'refs/tags/')
run: |
cd bindings/py
go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/}
- name: Fetch go package
if: startsWith(github.ref, 'refs/tags/') == false
run: |
cd bindings/py
go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0)
- name: Prebuild windows extension
run: |
sudo apt-get install mingw-w64
cd bindings/py
CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o _minify.so
- name: Upload go library
uses: actions/upload-artifact@v3
with:
name: minify-windows-${{ matrix.go_target }}.so
path: bindings/py/_minify.so

windows:
runs-on: windows-latest
needs: windows-go-crosscompile
strategy:
matrix:
include:
- go_target: amd64
cibw_target: AMD64
#- go_target: 386
# cibw_target: x86
#- go_target: arm64
# cibw_target: ARM64
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: minify-windows-${{ matrix.go_target }}.so
path: bindings/py/src/minify

- name: Build wheels
uses: pypa/[email protected]
with:
package-dir: bindings/py
env:
CIBW_ARCHS: ${{ matrix.cibw_target }}
CIBW_BUILD_VERBOSITY: 1

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-windows-${{ matrix.go_target }}
path: ./wheelhouse/*.whl

macos-go-crosscompile:
if: false
runs-on: ubuntu-latest
strategy:
matrix:
include:
- go_target: amd64
clang_target: x86_64
- go_target: arm64
clang_target: arm64
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-go@v4
with:
go-version: '>=1.17'
- name: Fetch go package
if: startsWith(github.ref, 'refs/tags/')
run: |
cd bindings/py
go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/}
- name: Fetch go package
if: startsWith(github.ref, 'refs/tags/') == false
run: |
cd bindings/py
go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0)
- name: Prebuild macos extension
run: |
cd bindings/py
export CGO_ENABLED=1
export GOOS=darwin
export GOARCH=${{ matrix.go_target }}
#export CFLAGS="-Wno-error=unused-command-line-argument -target ${{ matrix.clang_target }}-unknown-darwin-unknown"
export CC=gcc
go build -buildmode=c-shared -o minify.so
- name: Upload go library
uses: actions/upload-artifact@v3
with:
name: minify-darwin-${{ matrix.go_target }}.so
path: bindings/py/minify.so
macos:
if: false
runs-on: macos-latest
needs: macos-go-crosscompile
strategy:
matrix:
include:
- go_target: amd64
cibw_target: x86_64
#- go_target: arm64
# cibw_target: arm64
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: minify-darwin-${{ matrix.go_target }}.so
path: bindings/py/src/minify/_minify.so
- uses: actions/setup-python@v4
with:
python-version: '3.11'
#- uses: actions/setup-go@v4
# with:
# go-version: '>=1.17'

- name: Build wheels
uses: pypa/[email protected]
with:
package-dir: bindings/py
env:
CIBW_ARCHS: ${{ matrix.cibw_target }}
#CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }} CGO_ENABLED=1'
#CIBW_BEFORE_ALL: cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-macos-${{ matrix.go_target }}
path: ./wheelhouse/*.whl

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: pip install build
- name: Build package
run: |
cd bindings/py
python -m build --sdist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: bindings/py/dist/*

release:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
#needs: [linux, windows, macos, sdist]
needs: [linux, windows, sdist]
steps:
- name: Collect artifacts
uses: actions/download-artifact@v3
with:
path: dist
- name: Omit non-release files
run: rm dist/*.so
- name: Upload to GitHub Release
uses: softprops/[email protected]
with:
files: dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ bindings/js/example/node_modules
bindings/js/example/test.min.html
bindings/py/go.mod
bindings/py/go.sum
bindings/py/minify.h
bindings/py/minify.so
bindings/py/tdewolff_minify.egg-info
bindings/py/**/*.h
bindings/py/**/*.so
bindings/py/**/*.egg-info
bindings/py/example/example.min.html
bindings/py/dist
bindings/py/build
bindings/py/**/*.pyc
Loading

0 comments on commit 2281e8e

Please sign in to comment.