Update build_shared.yml #55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Shared Libraries | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
update-version-for-r: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Git | |
run: sudo apt-get install git | |
- name: Determine Version | |
id: versioning | |
run: | | |
if [[ $GITHUB_REF =~ refs/tags/v* ]]; then | |
# If build is triggered by a tag | |
VERSION=${GITHUB_REF#refs/tags/v} | |
else | |
# If build is triggered by a branch push without a tag, use the latest tag from main | |
VERSION=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
VERSION=${VERSION#v} # Strip 'v' prefix if present in tags | |
fi | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
echo "Version determined: ${VERSION}" | |
- name: Update DESCRIPTION File | |
run: | | |
sed -i "s/^Version:.*/Version: ${{ env.VERSION }}/" r-package/DESCRIPTION | |
- name: Commit and push if changes | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add r-package/DESCRIPTION | |
git diff --staged --quiet || (git commit -m "Update version to ${{ env.VERSION }}" && git push) | |
build-linux-amd64: | |
name: Build Linux Shared Library | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.21' | |
- name: Build shared library for Linux | |
working-directory: sharedlib | |
run: | | |
go build -buildmode=c-shared -o libprismaid_linux_amd64.so export.go | |
- name: Upload Linux shared library artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-amd64-shared-library | |
path: sharedlib/libprismaid_linux_amd64.so | |
- name: Commit and push changes | |
run: | | |
cp sharedlib/libprismaid_linux_amd64.so r-package/inst/libs/linux/libprismaid_linux_amd64.so | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git fetch origin main | |
git checkout main | |
git pull origin main | |
git add r-package/inst/libs/linux/libprismaid_linux_amd64.so | |
git diff --staged --quiet || (git commit -m "Update linux lib." && git push origin main) | |
build-windows-amd64: | |
name: Build Windows Shared Library | |
runs-on: windows-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.21' | |
- name: Build shared library for Windows | |
working-directory: sharedlib | |
shell: pwsh | |
run: | | |
go build -buildmode=c-shared -o libprismaid_windows_amd64.dll .\export.go | |
- name: Upload Windows shared library artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: windows-amd64-shared-library | |
path: sharedlib/libprismaid_windows_amd64.dll | |
- name: Commit and push changes | |
run: | | |
cp sharedlib/libprismaid_windows_amd64.dll r-package/inst/libs/windows/libprismaid_windows_amd64.dll | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git fetch origin main | |
git checkout main | |
git pull origin main | |
git add r-package/inst/libs/windows/libprismaid_windows_amd64.dll | |
git diff --staged --quiet || (git commit -m "Update Windows lib." && git push origin main) | |
build-macos-arm64: | |
name: Build macOS Arm64 Shared Library | |
runs-on: macos-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.21' | |
- name: Build shared library for macOS | |
working-directory: sharedlib | |
run: | | |
go build -buildmode=c-shared -o libprismaid_darwin_arm64.dylib export.go | |
- name: Upload macOS shared library artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: macos-arm64-shared-library | |
path: sharedlib/libprismaid_darwin_arm64.dylib | |
- name: Commit and push changes | |
run: | | |
cp sharedlib/libprismaid_darwin_arm64.dylib r-package/inst/libs/macos/libprismaid_darwin_arm64.dylib | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git fetch origin main | |
git checkout main | |
git pull origin main | |
git add r-package/inst/libs/macos/libprismaid_darwin_arm64.dylib | |
git diff --staged --quiet || (git commit -m "Update macOS lib." && git push origin main) | |
package-python: | |
name: Package Python Project with All Shared Libraries | |
runs-on: ubuntu-latest | |
needs: [build-linux-amd64, build-windows-amd64, build-macos-arm64] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Copy files for Build | |
run: | | |
cp README.md python/README.md | |
cp LICENSE python/LICENSE | |
# Download artifacts from build jobs | |
- name: Download macOS shared library artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: macos-arm64-shared-library | |
path: python/prismaid/ | |
- name: Download Linux shared library artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: linux-amd64-shared-library | |
path: python/prismaid/ | |
- name: Download Windows shared library artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: windows-amd64-shared-library | |
path: python/prismaid/ | |
- name: Install build tools | |
working-directory: ./python | |
run: | | |
python -m pip install --upgrade pip setuptools wheel build | |
- name: Build Python package | |
working-directory: ./python | |
run: | | |
python -m build | |
- name: Upload Python Package Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: prismaid-python-package | |
path: python/dist/*.whl | |
publish-to-pypi: | |
name: Publish Python distribution to PyPI | |
needs: package-python # Ensure it waits for the packaging job | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download Python Package Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: prismaid-python-package | |
path: dist/ | |
- name: Install Twine | |
run: python -m pip install --upgrade twine | |
- name: Publish distribution to PyPI | |
env: | |
TWINE_USERNAME: "__token__" | |
TWINE_PASSWORD: "${{ secrets.PYPY_API_TOKEN }}" | |
run: | | |
twine upload --repository-url https://upload.pypi.org/legacy/ dist/* | |