Skip to content

Package Libraries

Package Libraries #175

Workflow file for this run

name: Package Libraries
on:
workflow_dispatch:
inputs:
release_name:
description: 'Release name for manual dispatch'
required: true
# Workflow dependencies, also to avoid concurrent commits
# Ref.: https://github.com/orgs/community/discussions/26238
workflow_run:
workflows: ["Generate Libraries code source"]
types:
- completed
jobs:
package-libs:
runs-on: ubuntu-latest
# PyPi trusted publishing | Ref.: https://github.com/pypa/gh-action-pypi-publish?tab=readme-ov-file#trusted-publishing
permissions:
contents: write # For final commit
packages: write # For package upload
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
# Run if this is a direct workflow_dispatch OR if the Generate Model workflow completed successfully after a release event
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release')
steps:
- name: Set RELEASE_VERSION based on the trigger type
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Workflow triggered via workflow_dispatch"
RELEASE_VERSION="${{ github.event.inputs.release_name }}"
elif [[ "${{ github.event.workflow_run.event }}" == "release" ]]; then
echo "Workflow triggered via Generate Model release"
RELEASE_VERSION="${{ github.event.workflow_run.head_branch }}"
else
echo "Workflow triggered via unsupported event"
exit 1
fi
# Make the RELEASE_VERSION semver compatible (replacing non letter/digit/./+ chars with .)
RELEASE_VERSION=$(echo "$RELEASE_VERSION" | sed 's/[^a-zA-Z0-9\.\+]/./g')
# Display the RELEASE_VERSION for verification
echo "The RELEASE_VERSION is: $RELEASE_VERSION"
# Check if RELEASE_VERSION matches the semver allowed pattern
if [[ ! $RELEASE_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9].* ]]; then
echo "RELEASE_VERSION is NOT semver compatible (1.1.1.xxx)"
exit 1
fi
# Export the RELEASE_VERSION environment variable for future steps (in env.RELEASE_VERSION)
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Install node env 🏗
uses: actions/setup-node@v4
with:
node-version: 16
# - name: Python - Prepare package files
# working-directory: ./generator_python/
# run: |
# # Add key package files
# cp pyproject.toml ./package/
# cp README.md ./package/
#
# # Generate __init__.py file to import all the *_wrapper classes
# echo "# Auto-generated imports" > ./package/src/hubsante_model/__init__.py
# find ./package/src/hubsante_model -type f -name "*_wrapper.py" | while read -r file; do
# # Extract the relative path from hubsante_model/
# rel_path=${file#*hubsante_model/}
# # Convert path to Python import format
# import_path=${rel_path%.py}
# import_path=${import_path//\//.}
# # Add import line
# echo "from .$import_path import *" >> ./package/src/hubsante_model/__init__.py
# done
#
# - name: Python - Set up
# uses: actions/setup-python@v4
# with:
# python-version: '3.8'
#
# - name: Python - Build package
# working-directory: ./generator_python/package/
# run: |
# pip install --upgrade build
# # Set correct version
# sed -i "s/version = .*/version = \"${{ env.RELEASE_VERSION }}\"/" pyproject.toml
# python -m build
#
# - name: Python - Upload package as artifact
# uses: actions/upload-artifact@v4
# with:
# name: python-package-artifact
# path: ./generator_python/package/dist/
#
# # Leverages trusted publisher | Ref.: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
# - name: Python - Publish package to pypi
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# packages-dir: ./generator_python/package/dist/
- name: Ruby - Set up
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Ruby - Build Gem
working-directory: ./generator_ruby/gem/
run: |
GEM_VERSION=${{ env.RELEASE_VERSION }}
export GEM_VERSION=${GEM_VERSION//+/.}
gem build hubsante_model.gemspec
- name: Ruby - Upload Gem as artifact
uses: actions/upload-artifact@v4
with:
name: ruby-gem-artifact
path: ./generator_ruby/gem/hubsante_model-*.gem
- name: Ruby - Push Gem to GitHub Packages
working-directory: ./generator_ruby/gem/
run: gem push --key github --host https://rubygems.pkg.github.com/ansforge ./hubsante_model-*.gem
env:
GEM_HOST_API_KEY: ${{ secrets.GITHUB_TOKEN }} # GitHub token used to authenticate
# - name: C# - Prepare package files
# working-directory: ./generator_csharp/
# run: |
# # Add key package files
# cp HubsanteModel.csproj ./package/src/
# cp README.md ./package/
# - name: C# - Set up .NET
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: '6.0.x'
# - name: C# - Build package
# working-directory: ./generator_csharp/package/src/
# run: |
# dotnet restore
# dotnet build --configuration Release
# dotnet pack --configuration Release -p:Version=${{ env.RELEASE_VERSION }}
# - name: C# - Upload package as artifact
# uses: actions/upload-artifact@v4
# with:
# name: csharp-package-artifact
# path: ./generator_csharp/package/src/bin/Release/*.nupkg
# - name: C# - Push package to GitHub Packages
# working-directory: ./generator_csharp/package/src/
# run: |
# dotnet nuget push bin/Release/*.nupkg --source https://nuget.pkg.github.com/ansforge/index.json --api-key ${{ secrets.GITHUB_TOKEN }}