Skip to content

Commit

Permalink
ci(pypi): call reusable workflow to handle PyPI Publish Job
Browse files Browse the repository at this point in the history
  • Loading branch information
boromir674 committed Nov 12, 2023
1 parent df70a8a commit 8ddab2a
Showing 1 changed file with 109 additions and 102 deletions.
211 changes: 109 additions & 102 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@ jobs:
with:
reference: "master"
tag: "${{ github.ref }}"
- run: echo "ON_MAIN_BRANCH=${{ steps.main_contains_tag.outputs.retval }}" >> $GITHUB_OUTPUT

- uses: rickstaa/action-contains-tag@v1
id: release_contains_tag
with:
reference: "release"
tag: "${{ github.ref }}"
- run: echo "ON_RELEASE_BRANCH=${{ steps.release_contains_tag.outputs.retval }}" >> $GITHUB_OUTPUT

- name: Pick Production or Test Environment, if tag on master or release branch respectively
id: set_environment_name
run: |
Expand All @@ -443,117 +443,124 @@ jobs:
echo "[DEBUG] ${{ github.ref }}"
DEPLOY=false
fi
echo "SELECTED_ENVIRONMENT=$ENVIRONMENT_NAME" >> $GITHUB_ENV
echo "AUTOMATED_DEPLOY=$DEPLOY" >> $GITHUB_ENV
- run: echo "[DEBUG] Branch name ${GITHUB_REF_NAME}"
- run: echo " ==== ${SELECTED_ENVIRONMENT} ===="
- run: echo " ==== ${AUTOMATED_DEPLOY} ===="

- name: Set Output for other Jobs to receive
id: set_job_outputs
run: |
echo " --- Selected ENV NAME: $SELECTED_ENVIRONMENT "
echo "ENVIRONMENT_NAME=${SELECTED_ENVIRONMENT}" >> $GITHUB_OUTPUT
echo " --- Signal OK for Automated Deployment?: $AUTOMATED_DEPLOY "
echo "AUTOMATED_DEPLOY=${AUTOMATED_DEPLOY}" >> $GITHUB_OUTPUT
echo "SELECTED_ENVIRONMENT=$ENVIRONMENT_NAME" >> $GITHUB_OUTPUT
echo "AUTOMATED_DEPLOY=$DEPLOY" >> $GITHUB_OUTPUT
- run: echo "ENVIRONMENT_NAME=${{ steps.set_environment_name.outputs.SELECTED_ENVIRONMENT }}" >> $GITHUB_OUTPUT
id: select_pypi_env
- run: echo "AUTOMATED_DEPLOY=${{ steps.set_environment_name.outputs.AUTOMATED_DEPLOY }}" >> $GITHUB_OUTPUT
id: auto_pypi_deploy
outputs:
ENVIRONMENT_NAME: ${{ steps.set_job_outputs.outputs.ENVIRONMENT_NAME }}
AUTOMATED_DEPLOY: ${{ steps.set_job_outputs.outputs.AUTOMATED_DEPLOY }}
ENVIRONMENT_NAME: ${{ steps.select_pypi_env.outputs.ENVIRONMENT_NAME }}
AUTOMATED_DEPLOY: ${{ steps.auto_pypi_deploy.outputs.AUTOMATED_DEPLOY }}

### PYPI UPLOAD JOB ###
pypi_publish:
pypi_publ:
needs: [test_suite, check_which_git_branch_we_are_on]
# needs: check_which_git_branch_we_are_on
runs-on: ubuntu-latest
# if we are on tag starting with "v" and if we are on master or release branch
if: ${{ startsWith(github.event.ref, 'refs/tags/v') && needs.check_which_git_branch_we_are_on.outputs.AUTOMATED_DEPLOY == 'true' }}
environment:
name: ${{ needs.check_which_git_branch_we_are_on.outputs.ENVIRONMENT_NAME }}
env:
DIST_DIR: dist
DISTRO_SEMVER: ${{ needs.test_suite.outputs.SEMVER_PIP_FORMAT }} # required env var by deploy script (tox -e deploy)
TWINE_USERNAME: ${{ vars.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
PYPI_SERVER: ${{ vars.PYPI_SERVER }}
steps:
- uses: actions/checkout@v3
- name: Download Source & Wheel distributions
uses: actions/download-artifact@v3
with:
path: downloaded-artifacts
- name: Get Publishable files from the Artifacts
run: |
TAG="${GITHUB_REF_NAME}"
TAG_SEM_VER="${TAG:1}" # remove the first character (v)
if: startsWith(github.event.ref, 'refs/tags/v') && needs.check_which_git_branch_we_are_on.outputs.AUTOMATED_DEPLOY
uses: boromir674/automated-workflows/.github/workflows/pypi_env.yml@test
with:
distro_name: "artificial_artwork"
distro_version: ${{ needs.test_suite.outputs.SEMVER_PIP_FORMAT }}
should_trigger: true
# does not affect the job, but is used to name the artifacts folder
artifacts_path: "downloaded-artifacts"
pypi_env: ${{ needs.check_which_git_branch_we_are_on.outputs.ENVIRONMENT_NAME }}
# optional
dist_folder: "dist"

# Make sure the distro semver ($DISTRO_SEMVER), which is identical
# to the version string in the source code, when its format is
# Major.Minor.Patch (and slightly different when its format is M.m.p-prerelase),
# is simillarly either identical or slightly different
# when compared to the git tag ($TAG_SEM_VER)
### PYPI UPLOAD JOB ###
# pypi_publish:
# needs: [test_suite, check_which_git_branch_we_are_on]
# # needs: check_which_git_branch_we_are_on
# runs-on: ubuntu-latest
# # if we are on tag starting with "v" and if we are on master or release branch
# if: ${{ startsWith(github.event.ref, 'refs/tags/v') && needs.check_which_git_branch_we_are_on.outputs.AUTOMATED_DEPLOY == 'true' }}
# environment:
# name: ${{ needs.check_which_git_branch_we_are_on.outputs.ENVIRONMENT_NAME }}
# env:
# DIST_DIR: dist
# DISTRO_SEMVER: ${{ needs.test_suite.outputs.SEMVER_PIP_FORMAT }} # required env var by deploy script (tox -e deploy)
# TWINE_USERNAME: ${{ vars.TWINE_USERNAME }}
# TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
# PYPI_SERVER: ${{ vars.PYPI_SERVER }}
# steps:
# - uses: actions/checkout@v3
# - name: Download Source & Wheel distributions
# uses: actions/download-artifact@v3
# with:
# path: downloaded-artifacts
# - name: Get Publishable files from the Artifacts
# run: |
# TAG="${GITHUB_REF_NAME}"
# TAG_SEM_VER="${TAG:1}" # remove the first character (v)

# # Make sure the distro semver ($DISTRO_SEMVER), which is identical
# # to the version string in the source code, when its format is
# # Major.Minor.Patch (and slightly different when its format is M.m.p-prerelase),
# # is simillarly either identical or slightly different
# # when compared to the git tag ($TAG_SEM_VER)

# for now MUST match only the Major.Minor.Patch part
# # for now MUST match only the Major.Minor.Patch part

# Extract Major.Minor.Patch parts from DISTRO_SEMVER and TAG_SEM_VER
DISTRO_MMP=$(echo "$DISTRO_SEMVER" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
TAG_MMP=$(echo "$TAG_SEM_VER" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
if [ "$DISTRO_MMP" = "$TAG_MMP" ]; then
echo "Major.Minor.Patch part of DISTRO_SEMVER matches TAG_SEM_VER"
else
echo "[ERROR] Major.Minor.Patch part of DISTRO_SEMVER does not match TAG_SEM_VER"
echo "DISTRO_SEMVER=$DISTRO_SEMVER"
echo "TAG_SEM_VER=$TAG_SEM_VER"
echo "DISTRO_MMP=$DISTRO_MMP"
echo "TAG_MMP=$TAG_MMP"
exit 1
fi
echo "PACKAGE_DIST_VERSION=$DISTRO_SEMVER" >> $GITHUB_ENV
- run: mkdir ${DIST_DIR}
- run: |
# Get Source Distribution (tar.gz of source code)
source_distributions=$(find downloaded-artifacts -type f -name artificial_artwork*.tar.gz)
source_distributions_array=($source_distributions)
source_distribution=${source_distributions_array[0]} # a *.tar.gz file path
# Extract the base name (without the path)
source_distribution_name=$(basename "$source_distribution")
# Check if all source distribution (.tar.gz) files have the same name
for file in "${source_distributions_array[@]}"; do
if [ "$source_distribution_name" != "$(basename "$file")" ]; then
echo "Error: Not all Source Distribution .tar.gz files have the same name!"
exit 1
fi
done
echo " -- Will Upload : $source_distribution_name -- "
echo "source_distribution=$source_distribution" >> $GITHUB_ENV
cp "$source_distribution" ${DIST_DIR}
- run: |
# Get all built Wheels and copy to dist folder
for f in `find downloaded-artifacts -type f -name artificial_artwork*.whl`; do
echo "F: $f";
# TODO check for duplicates, which means that our build matrix produces the same wheel (need a different compiler that python such as pypy, cython, etc)
cp $f ${DIST_DIR}
done
- name: Install Dependencies
run: pip install tox==3.28

- run: echo "Publishing $PACKAGE_DIST_VERSION to $PYPI_SERVER PyPI"

- name: Publish to PyPI
# env:
# TWINE_USERNAME: ${{ vars.TWINE_USERNAME }}
# TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
# PYPI_SERVER: ${{ vars.PYPI_SERVER }}
# run: tox -vv -s false -e deploy
run: tox -vv -s false -e deploy -- upload --non-interactive --skip-existing
# # Extract Major.Minor.Patch parts from DISTRO_SEMVER and TAG_SEM_VER
# DISTRO_MMP=$(echo "$DISTRO_SEMVER" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
# TAG_MMP=$(echo "$TAG_SEM_VER" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
# if [ "$DISTRO_MMP" = "$TAG_MMP" ]; then
# echo "Major.Minor.Patch part of DISTRO_SEMVER matches TAG_SEM_VER"
# else
# echo "[ERROR] Major.Minor.Patch part of DISTRO_SEMVER does not match TAG_SEM_VER"
# echo "DISTRO_SEMVER=$DISTRO_SEMVER"
# echo "TAG_SEM_VER=$TAG_SEM_VER"
# echo "DISTRO_MMP=$DISTRO_MMP"
# echo "TAG_MMP=$TAG_MMP"
# exit 1
# fi
# echo "PACKAGE_DIST_VERSION=$DISTRO_SEMVER" >> $GITHUB_ENV
# - run: mkdir ${DIST_DIR}
# - run: |
# # Get Source Distribution (tar.gz of source code)
# source_distributions=$(find downloaded-artifacts -type f -name artificial_artwork*.tar.gz)
# source_distributions_array=($source_distributions)
# source_distribution=${source_distributions_array[0]} # a *.tar.gz file path
# # Extract the base name (without the path)
# source_distribution_name=$(basename "$source_distribution")
# # Check if all source distribution (.tar.gz) files have the same name
# for file in "${source_distributions_array[@]}"; do
# if [ "$source_distribution_name" != "$(basename "$file")" ]; then
# echo "Error: Not all Source Distribution .tar.gz files have the same name!"
# exit 1
# fi
# done
# echo " -- Will Upload : $source_distribution_name -- "
# echo "source_distribution=$source_distribution" >> $GITHUB_ENV
# cp "$source_distribution" ${DIST_DIR}

# - run: |
# # Get all built Wheels and copy to dist folder
# for f in `find downloaded-artifacts -type f -name artificial_artwork*.whl`; do
# echo "F: $f";
# # TODO check for duplicates, which means that our build matrix produces the same wheel (need a different compiler that python such as pypy, cython, etc)
# cp $f ${DIST_DIR}
# done
# - name: Install Dependencies
# run: pip install tox==3.28

# - run: echo "Publishing $PACKAGE_DIST_VERSION to $PYPI_SERVER PyPI"

# - name: Publish to PyPI
# # env:
# # TWINE_USERNAME: ${{ vars.TWINE_USERNAME }}
# # TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
# # PYPI_SERVER: ${{ vars.PYPI_SERVER }}
# # run: tox -vv -s false -e deploy
# run: tox -vv -s false -e deploy -- upload --non-interactive --skip-existing

# runs: twine upload --non-interactive --repository testpypi --skip-existing ./dist/PY_PACKAGE-:Version.tar.gz --verbose
# # runs: twine upload --non-interactive --repository testpypi --skip-existing ./dist/PY_PACKAGE-:Version.tar.gz --verbose

# runs: twine upload --non-interactive --skip-existing --repository testpypi --skip-existing ./dist/PY_PACKAGE-:Version.tar.gz --verbose
# # runs: twine upload --non-interactive --skip-existing --repository testpypi --skip-existing ./dist/PY_PACKAGE-:Version.tar.gz --verbose

- run: echo "Published :\)"
# - run: echo "Published :\)"


## AUTOMATED DOCKER BUILD and PUBLISH ON DOCKERHUB ##
Expand Down

0 comments on commit 8ddab2a

Please sign in to comment.