|
| 1 | +name: Release on push to `main` |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + paths: |
| 7 | + - pyproject.toml |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + publish-if-new-version: |
| 12 | + if: github.repository != 'UWIT-IAM/example-flask-app' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 2 |
| 18 | + |
| 19 | + # Only publish if the version has changed; otherwise, we would be |
| 20 | + # re-publishing existing stuff without updating the version, and that |
| 21 | + # could cause problems. |
| 22 | + - name: Check if the change should be published |
| 23 | + if: github.event_name != 'workflow_dispatch' |
| 24 | + run: | |
| 25 | + set -x |
| 26 | + publishable=false |
| 27 | + diff=$(git diff HEAD:pyproject.toml HEAD~1:pyproject.toml) || exit 0 |
| 28 | + echo "$diff" | grep '+version =' |
| 29 | + if [[ "$?" -ne 0 ]] |
| 30 | + then |
| 31 | + echo 'Not publishable - skipping' |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +
|
| 35 | + - uses: uwit-iam/action-setup-poetry-project@main |
| 36 | + id: auth |
| 37 | + with: |
| 38 | + credentials: "${{ secrets.MCI_GCLOUD_AUTH_JSON }}" |
| 39 | + enable_private_docker: true |
| 40 | + enable_private_pypi: true |
| 41 | + |
| 42 | + - name: Run validation checks and tests |
| 43 | + run: | |
| 44 | + poetry run pytest |
| 45 | + poetry run flake8 |
| 46 | + poetry run black --check . |
| 47 | +
|
| 48 | + - name: Calculate versioning variables |
| 49 | + id: get-version |
| 50 | + run: | |
| 51 | + echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT |
| 52 | + echo "timestamp=$(date --utc +%Y.%m.%d.%H.%M.%S)" >> $GITHUB_OUTPUT |
| 53 | +
|
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + - name: Build and push Docker image |
| 58 | + uses: docker/build-push-action@v5 |
| 59 | + with: |
| 60 | + context: . |
| 61 | + file: ./Dockerfile |
| 62 | + push: true |
| 63 | + target: app |
| 64 | + tags: | |
| 65 | + us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name}:${{ steps.get-version.outputs.version }} |
| 66 | + us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name}:deploy-dev.${{ steps.get-version.outputs.timestamp }}.v${{ steps.get-version.outputs.version }} |
| 67 | + secret-files: | |
| 68 | + "gcloud_auth_credentials=${{ steps.auth.outputs.credentials_file_path }}" |
| 69 | +
|
0 commit comments