Skip to content

Update build_shared.yml #58

Update build_shared.yml

Update build_shared.yml #58

Workflow file for this run

name: Build and Deploy Shared Libraries
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
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
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
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: Install GitHub CLI
run: sudo apt-get install gh -y
- 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 -b update-linux-lib-${GITHUB_RUN_ID}
git add r-package/inst/libs/linux/libprismaid_linux_amd64.so
git diff --staged --quiet || git commit -m "Update Linux lib."
git push origin update-linux-lib-${GITHUB_RUN_ID}
# Create Pull Request
gh pr create --title "Update Linux Library" --body "Auto-update by CI/CD." --base main --head update-linux-lib-${GITHUB_RUN_ID}
# Automatically approve and merge the PR (requires GitHub token)
gh pr merge --auto --squash --delete-branch
build-windows-amd64:
name: Build Windows Shared Library
runs-on: windows-latest
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
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: Install GitHub CLI on Windows
run: |
choco install gh -y
- name: Commit and push changes for Windows
shell: bash
run: |
copy 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 -b update-windows-lib-${GITHUB_RUN_ID}
git add r-package/inst/libs/windows/libprismaid_windows_amd64.dll
git diff --staged --quiet || git commit -m "Update Windows lib."
git push origin update-windows-lib-${GITHUB_RUN_ID}
# Create Pull Request
gh pr create --title "Update Windows Library" --body "Auto-update by CI/CD." --base main --head update-windows-lib-${GITHUB_RUN_ID}
# Automatically approve and merge the PR
gh pr merge --auto --squash --delete-branch
build-macos-arm64:
name: Build macOS Arm64 Shared Library
runs-on: macos-latest
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
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: Install GitHub CLI on macOS
run: brew install gh
- name: Commit and push changes for macOS
shell: bash
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 -b update-macos-lib-${GITHUB_RUN_ID}
git add r-package/inst/libs/macos/libprismaid_darwin_arm64.dylib
git diff --staged --quiet || git commit -m "Update macOS lib."
git push origin update-macos-lib-${GITHUB_RUN_ID}
# Create Pull Request
gh pr create --title "Update macOS Library" --body "Auto-update by CI/CD." --base main --head update-macos-lib-${GITHUB_RUN_ID}
# Automatically approve and merge the PR
gh pr merge --auto --squash --delete-branch
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/*