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

Aligning pipeline to other solutions #7

Merged
merged 2 commits into from
Dec 15, 2023
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
120 changes: 1 addition & 119 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
workflow_dispatch:
push:
branches:
- '**'
- "main"
- staging
- 'feature/**'
Expand Down Expand Up @@ -148,23 +149,6 @@ jobs:
working-directory: ${{ env.APP_PWD }}
run: pip install "dist/${{ env.WHL_NAME }}"

- name: Check Unit Test Files
id: check_test_files
uses: andstor/file-existence-action@v2
with:
files: "*/tests/test_*.py"

# - name: Run Tests with pytest
# id: tests_pytest
# if: steps.check_test_files.outputs.files_exists == 'true'
# working-directory: ${{ env.APP_PWD }}
# run: pytest

# - name: Unittest
# id: test_unittest
# if: steps.check_test_files.outputs.files_exists == 'true'
# working-directory: ${{ env.APP_PWD }}
# run: python -m unittest

- name: Copy wheel
id: copy_whl
Expand All @@ -180,108 +164,6 @@ jobs:
path: ${{ env.APP_PWD }}/dist/${{ env.PYTHON_VERSION }}/${{ env.WHL_NAME }}
key: ${{ env.PYTHON_VERSION }}_${{ env.APP_DIR }}_${{ github.run_id }}


publish-staging:
if: ${{ github.ref == 'refs/heads/staging'}}
needs: [build-and-test]
runs-on: ubuntu-latest

steps:
- name: Get Environment Variables
id: get_env_vars
run: |
echo "MIN_PY_VER=${{ needs.build-and-test.outputs.min_py_ver }}" >> $GITHUB_ENV
echo "APP_PWD=${{ needs.build-and-test.outputs.app_pwd }}" >> $GITHUB_ENV
echo "APP_DIR=${{ needs.build-and-test.outputs.app_dir }}" >> $GITHUB_ENV
echo "VERSION=${{ needs.build-and-test.outputs.version }}" >> $GITHUB_ENV
echo "WHL_NAME=${{ needs.build-and-test.outputs.whl_name }}" >> $GITHUB_ENV
echo "SOURCE_BRANCH=${{ needs.build-and-test.outputs.source_branch }}" >> $GITHUB_ENV
echo "AWS_REGION=eu-west-1" >> $GITHUB_ENV
echo "AWS_BUCKET=mend-ps-staging" >> $GITHUB_ENV
echo "AWS_DOMAIN=mend-ps" >> $GITHUB_ENV
echo "AWS_REPO=mend-ps-staging" >> $GITHUB_ENV

- name: Restore whl
id: restore_whl
uses: actions/cache@v3
with:
path: ${{ env.APP_PWD }}/dist/${{ env.MIN_PY_VER }}/${{ env.WHL_NAME }}
key: ${{ env.MIN_PY_VER }}_${{ env.APP_DIR }}_${{ github.run_id }}

- name: Configure AWS Credentials
id: config_aws_creds
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Configure AWS CodeArtifact
id: config_aws_codeartifact
working-directory: ${{ env.APP_PWD }}
run: |
pip install twine

twinePass="$(aws codeartifact get-authorization-token --domain ${{ env.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_ACCOUNT_ID }} --query authorizationToken --output text)"
twineRepo="$(aws codeartifact get-repository-endpoint --domain ${{ env.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_ACCOUNT_ID }} --repository ${{ env.AWS_REPO }} --format pypi --query repositoryEndpoint --output text)"
echo "TWINE_USERNAME=aws" >> $GITHUB_ENV
echo "TWINE_PASSWORD=$twinePass" >> $GITHUB_ENV
echo "TWINE_REPOSITORY_URL=$twineRepo" >> $GITHUB_ENV

- name: Upload to AWS CodeArtifact
id: upload_aws_codeartifact
working-directory: ${{ env.APP_PWD }}
run: |
twine upload --repository-url ${{ env.TWINE_REPOSITORY_URL }} "dist/${{ env.MIN_PY_VER }}/${{ env.WHL_NAME }}"

- name: Staging Version Upload Notification (TBD)
id: staging_upload_notification
working-directory: ${{ env.APP_PWD }}
run: |
echo "Package is ready for testing"
echo " App Name: ${{ env.APP_NAME }}"
echo " Version: ${{ env.VERSION }}"
echo ""
echo "To install, use the commands:"
echo ' CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain ${{ env.AWS_DOMAIN }} --domain-owner ${{ secrets.AWS_ACCOUNT_ID }} --region ${{ secrets.AWS_ACCOUNT_ID }} --query authorizationToken --output text`'
echo ' pip install --no-cache-dir --index-url=https://aws:$CODEARTIFACT_AUTH_TOKEN@${{ env.AWS_DOMAIN }}-${{ secrets.AWS_ACCOUNT_ID }}.d.codeartifact.${{ secrets.AWS_REGION }}.amazonaws.com/pypi/${{ secrets.AWS_REPO }}/simple/ ${{ env.APP_NAME }}'


publish-main:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/test')
needs: [build-and-test]
runs-on: ubuntu-latest

steps:
- name: Get Environment Variables
id: get_env_vars
run: |
echo "MIN_PY_VER=${{ needs.build-and-test.outputs.min_py_ver }}" >> $GITHUB_ENV
echo "APP_PWD=${{ needs.build-and-test.outputs.app_pwd }}" >> $GITHUB_ENV
echo "APP_DIR=${{ needs.build-and-test.outputs.app_dir }}" >> $GITHUB_ENV
echo "VERSION=${{ needs.build-and-test.outputs.version }}" >> $GITHUB_ENV
echo "WHL_NAME=${{ needs.build-and-test.outputs.whl_name }}" >> $GITHUB_ENV
echo "SOURCE_BRANCH=${{ needs.build-and-test.outputs.source_branch }}" >> $GITHUB_ENV

- name: Restore whl
id: restore_whl
uses: actions/cache@v3
with:
path: ${{ env.APP_PWD }}/dist/${{ env.MIN_PY_VER }}/${{ env.WHL_NAME }}
key: ${{ env.MIN_PY_VER }}_${{ env.APP_DIR }}_${{ github.run_id }}

- name: Publish to TestPyPI
id: publish_to_test_pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: false
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: dist/${{ needs.build-and-test.outputs.min_py_ver }}
repository-url: https://test.pypi.org/legacy/
print-hash: true


publish-release:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: [build-and-test]
Expand Down