|
| 1 | +name: publish_data-platform-data-diff |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + python_version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + poetry_version: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + python_cache_key: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + id-token: write |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: 'Publish python data-platform-data-diff' |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Setup AWS credentials |
| 27 | + uses: aws-actions/configure-aws-credentials@v1 |
| 28 | + with: |
| 29 | + role-to-assume: ${{ secrets.CROSS_ACCOUNT_ROLE_TO_ASSUME }} |
| 30 | + aws-region: ${{ secrets.AWS_REGION }} |
| 31 | + mask-aws-account-id: 'yes' |
| 32 | + |
| 33 | + - uses: actions/checkout@v3 |
| 34 | + |
| 35 | + - name: Setup Python |
| 36 | + id: setup-python |
| 37 | + uses: actions/setup-python@v4 |
| 38 | + with: |
| 39 | + python-version: '${{ inputs.python_version }}' |
| 40 | + |
| 41 | + - name: Install and configure Poetry |
| 42 | + uses: snok/install-poetry@v1 |
| 43 | + with: |
| 44 | + version: ${{ inputs.poetry_version }} |
| 45 | + virtualenvs-in-project: true |
| 46 | + |
| 47 | + - name: Restore cached key |
| 48 | + id: cache-restore |
| 49 | + uses: actions/cache/restore@v3 |
| 50 | + with: |
| 51 | + path: .venv |
| 52 | + key: ${{ inputs.python_cache_key }} |
| 53 | + |
| 54 | + - name: Install jq |
| 55 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 56 | + |
| 57 | + - name: Set env variables |
| 58 | + env: |
| 59 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 60 | + CODEARTIFACT_URL: ${{ secrets.CODEARTIFACT_URL }} |
| 61 | + run: | |
| 62 | + # Replace placeholder URL with actual repository URL |
| 63 | + sed -i "s|PLACEHOLDER_URL|$CODEARTIFACT_URL|" pyproject.toml |
| 64 | +
|
| 65 | + VERSION=$(poetry run toml get --toml-path pyproject.toml tool.poetry.version 2>/dev/null) || { echo "FAILED TO GET POETRY VERSION"; exit 1; } |
| 66 | + echo $VERSION > version.txt |
| 67 | + echo "CURRENT_VERSION=$(cat version.txt)" >> $GITHUB_ENV |
| 68 | +
|
| 69 | + - name: Check if version needs to be published |
| 70 | + if: ${{ github.ref_name == 'master' }} |
| 71 | + env: |
| 72 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 73 | + id: check_version |
| 74 | + run: | |
| 75 | + if ! aws codeartifact list-package-versions --region $AWS_REGION --domain coinlist --repository data-platform-data-diff --format pypi --package data_diff 2>/dev/null | grep -q "$(cat version.txt | sed 's/\./\\./g')"; then |
| 76 | + echo "skip_publish=false" >> $GITHUB_ENV |
| 77 | + else |
| 78 | + echo "skip_publish=true" >> $GITHUB_ENV |
| 79 | + fi |
| 80 | +
|
| 81 | + - name: Publish dev version |
| 82 | + if: ${{ github.ref_name != 'master' }} |
| 83 | + run: | |
| 84 | + DEV_VERSION="$CURRENT_VERSION-dev+${GITHUB_SHA:0:7}" |
| 85 | + echo $DEV_VERSION > version.txt |
| 86 | + poetry run toml set --toml-path pyproject.toml tool.poetry.version $DEV_VERSION || { echo "Failed to set dev version in pyproject.toml"; exit 1; } |
| 87 | + poetry config repositories.data-platform-data-diff ${{ secrets.CODEARTIFACT_URL }} |
| 88 | + poetry build --format wheel || { echo "Failed to build the wheel"; exit 1; } |
| 89 | + poetry publish --repository data-platform-data-diff --username aws --password $(aws codeartifact --region ${{ secrets.AWS_REGION }} get-authorization-token --domain coinlist --query authorizationToken --output text 2>/dev/null) || { echo "Failed to publish the dev package"; exit 1; } |
| 90 | +
|
| 91 | + - name: Publish new version |
| 92 | + if: ${{ github.ref_name == 'master' }} && ${{ env.skip_publish != 'true' }} |
| 93 | + run: | |
| 94 | + poetry build --format wheel 2>/dev/null || { echo "Failed to build the wheel"; exit 1; } |
| 95 | + poetry publish --repository data-platform-data-diff --username aws --password $(aws codeartifact --region ${{ secrets.AWS_REGION }} get-authorization-token --domain coinlist --query authorizationToken --output text 2>/dev/null) || { echo "Failed to publish the package"; exit 1; } |
0 commit comments