From 9bcfcdf0334357700be2f5047e7272c1b80eac53 Mon Sep 17 00:00:00 2001 From: Nolwen Date: Tue, 13 Sep 2022 16:35:55 +0200 Subject: [PATCH] Fix job dependency --- .github/workflows/build.yml | 67 ++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cae69c6..e8766a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build discrete-optimization +name: Build workflow-testing on: push: @@ -15,44 +15,65 @@ concurrency: cancel-in-progress: true jobs: - test-github-env: + build: runs-on: ubuntu-latest steps: - name: Checkout source code uses: actions/checkout@v2 - - name: test - run: | - echo ${{ github.workflow }}-${{ github.ref }} - echo $GITHUB_REF - echo ${{ github.ref }} - echo ${{ github.ref_name }} - echo ${{ github.head_ref }} - echo ${{ github.base_ref }} - echo ${{ github.repository }} - echo $GITHUB_REPOSITORY - echo ${{ github }} + - name: Install build dependencies + run: pip install -U setuptools wheel + - name: Update version number, according to pushed tag or `git describe` + run: | + # pushing tag or branch? + if [[ $GITHUB_REF == refs/tags/v* ]]; + then + # pushing tag: ensure using the tag pushed + DESCRIBE=${GITHUB_REF/refs\/tags\//} # stripping "refs/tags/" + else + # default: use git describe from previous tag matching *glob* pattern "v[0-9]*" + DESCRIBE=$(git describe --tags --match="v[0-9]*") + fi + VERSION=${DESCRIBE/v/} # stripping "v" + echo $VERSION + # Replace in-place version number in package __init__.py, also used by setup.py + sed -i -e "s/^__version__\s*=.*$/__version__ = \"${VERSION}\"/g" workflow_testing/__init__.py + cat workflow_testing/__init__.py + - name: Build workflow_testing wheel + run: python setup.py bdist_wheel + - name: Upload as build artifacts + uses: actions/upload-artifact@v2 + with: + name: wheels + path: dist/*.whl deploy: runs-on: ubuntu-latest - needs: test-github-env + needs: build if: startsWith(github.ref, 'refs/tags/v') steps: - - name: Checkout source code - uses: actions/checkout@v2 - - name: install build dependencies - run: pip install -U setuptools wheel - - name: Build workflow-testing wheel - run: python setup.py bdist_wheel - - name: rename dist as wheels - run: mv dist wheels + - name: Download wheels artifact + uses: actions/download-artifact@v1.0.0 + with: + name: wheels - name: Create the github release uses: softprops/action-gh-release@v1 with: files: wheels/*.whl generate_release_notes: true - - name: Publish package to TestPyPI + - name: Publish package to TestPyPI (only for forks) + env: + TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} + if: github.repository != 'airbus/workflow_testing' && env.TEST_PYPI_API_TOKEN != '' uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ packages_dir: wheels/ + - name: Publish package to PyPI (main repo) + env: + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + if: github.repository == 'airbus/workflow_testing' && env.PYPI_API_TOKEN != '' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + packages_dir: wheels/