Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pypi release #629

Merged
merged 27 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 101 additions & 29 deletions .github/workflows/on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ name: Build and publish to Docker Hub
on:
release:
# job will automatically run after a new "release" is create on github.
types: [created]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
dry_run:
description: 'If true, will not push the built images to docker hub.'
required: false
default: 'false'
types: [published]
#Allows you to run this workflow manually from the Actions tab

jobs:
# this job will build, test and (potentially) push the docker images to docker hub
Expand All @@ -29,6 +22,13 @@ jobs:
# - Pushes images (built at BUILD PHASE) to docker hub.
docker_build_and_publish:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
github_token: ${{ secrets.TOKEN_GITHUB }}
permissions:
id-token: write
contents: write # 'write' access to repository contents
pull-requests: write # 'write' access to pull requests
steps:
# BUILD PHASE
- name: Checkout
Expand All @@ -43,25 +43,14 @@ jobs:
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
if: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Get version tag from github release
if: github.event_name == 'release' && github.event.action == 'created'
run: |
echo "opal_version_tag=${{ github.event.release.tag_name }}" >> $GITHUB_ENV

- name: Get version tag from git history
if: ${{ !(github.event_name == 'release' && github.event.action == 'created') }}
run: |
echo "opal_version_tag=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

- name: Echo version tag
run: |
echo "The version tag that will be published to docker hub is: ${{ env.opal_version_tag }}"
echo "The version tag that will be published to docker hub is: ${{ github.event.release.tag_name }}"

- name: Build client for testing
id: build_client
Expand Down Expand Up @@ -114,52 +103,135 @@ jobs:
with:
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
push: true
target: client
cache-from: type=registry,ref=permitio/opal-client:latest
cache-to: type=inline
tags: |
permitio/opal-client:latest
permitio/opal-client:${{ env.opal_version_tag }}
permitio/opal-client:${{ github.event.release.tag_name }}

- name: Build client-standalone
id: build_push_client_standalone
uses: docker/build-push-action@v4
with:
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
push: true
target: client-standalone
cache-from: type=registry,ref=permitio/opal-client-standalone:latest
cache-to: type=inline
tags: |
permitio/opal-client-standalone:latest
permitio/opal-client-standalone:${{ env.opal_version_tag }}
permitio/opal-client-standalone:${{ github.event.release.tag_name }}

- name: Build server
id: build_push_server
uses: docker/build-push-action@v4
with:
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
push: true
target: server
cache-from: type=registry,ref=permitio/opal-server:latest
cache-to: type=inline
tags: |
permitio/opal-server:latest
permitio/opal-server:${{ env.opal_version_tag }}
permitio/opal-server:${{ github.event.release.tag_name }}

- name: Build & Push client cedar
id: build_push_client_cedar
uses: docker/build-push-action@v4
with:
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
push: true
target: client-cedar
cache-from: type=registry,ref=permitio/opal-client-cedar:latest
cache-to: type=inline
tags: |
permitio/opal-client-cedar:latest
permitio/opal-client-cedar:${{ env.opal_version_tag }}
permitio/opal-client-cedar:${{ github.event.release.tag_name }}

- name: Python setup
uses: actions/setup-python@v5
with:
python-version: '3.11.8'

# This is the root file representing the package for all the sub-packages.
- name: Bump version - packaging__.py
run: |
version_tag=${{ github.event.release.tag_name }}
version_tuple=$(echo $version_tag | sed 's/\./, /g')
sed -i "s/VERSION = (.*/VERSION = (${version_tuple})/" packages/__packaging__.py
cat packages/__packaging__.py
git config --local user.email "[email protected]"
git config --local user.name "elimoshkovich"
git add packages/__packaging__.py
git commit -m "Bump version to ${version_tag}"
EliMoshkovich marked this conversation as resolved.
Show resolved Hide resolved

- name: Cleanup setup.py and Build every sub-packages
EliMoshkovich marked this conversation as resolved.
Show resolved Hide resolved
run: |
pip install wheel
cd packages/opal-common/ ; rm -rf *.egg-info build/ dist/
python setup.py sdist bdist_wheel
cd ../..
cd packages/opal-client/ ; rm -rf *.egg-info build/ dist/
python setup.py sdist bdist_wheel
cd ../..
cd packages/opal-server/ ; rm -rf *.egg-info build/ dist/
python setup.py sdist bdist_wheel
cd ../..

# Upload package distributions to the release - All assets in one step
- name: Upload assets to release
EliMoshkovich marked this conversation as resolved.
Show resolved Hide resolved
uses: shogo82148/[email protected]
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: |
packages/opal-common/dist/*
packages/opal-client/dist/*
packages/opal-server/dist/*

# Publish package distributions to PyPI
- name: Publish package distributions to PyPI - Opal-Common
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: packages/opal-common/dist/
# For Test only !
# password: ${{ secrets.TEST_PYPI_TOKEN }}
# repository-url: https://test.pypi.org/legacy/
env:
name: pypi
url: https://pypi.org/p/opal-common

- name: Publish package distributions to PyPI - Opal-Client
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: packages/opal-client/dist/
# For Test only !
# password: ${{ secrets.TEST_PYPI_TOKEN }}
# repository-url: https://test.pypi.org/legacy/
env:
name: pypi
url: https://pypi.org/p/opal-client

- name: Publish package distributions to PyPI - Opal-Server
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: packages/opal-server/dist/
# For Test only !
# password: ${{ secrets.TEST_PYPI_TOKEN }}
# repository-url: https://test.pypi.org/legacy/
env:
name: pypi
url: https://pypi.org/p/opal-server

- name: Push changes of packages/__packaging__.py to GitHub
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.TOKEN_GITHUB }}
branch: master
Loading