Skip to content

Rollback Pydantic version from V2 to V1 #624

Rollback Pydantic version from V2 to V1

Rollback Pydantic version from V2 to V1 #624

Workflow file for this run

name: Deploy to Athena Test
on:
pull_request:
types: [labeled]
permissions: write-all
jobs:
# Get an up to date version of the label list. github.event.pull_request.labels seems to sometimes be outdated
# if the run was waiting for a while, which can cause duplicate deployments
get-labels:
runs-on: ubuntu-latest
outputs:
labels: ${{ steps.get-labels.outputs.result }}
steps:
- name: Get PR labels
id: get-labels
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const labels = response.data
return labels.map(label => label.name)
# Check that the build job has run successfully before deploying
check-build-status:
needs: [ get-labels ]
runs-on: ubuntu-latest
# Only run workflow if the added label is a deploy label
if: contains(needs.get-labels.outputs.labels, 'deploy:athena-test3')
steps:
- name: Get latest successful build for branch
id: check_build
uses: octokit/request-action@v2.x
with:
route: GET /repos/${{ github.repository }}/actions/workflows/build.yml/runs?event=pull_request&status=success&head_sha=${{ github.event.pull_request.head.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Remove deployment-error label if new run is started
- uses: actions-ecosystem/action-remove-labels@v1
if: fromJSON(steps.check_build.outputs.data).total_count > 0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: |
deployment-error
# In case of invalid build status, remove deploy labels
- uses: actions-ecosystem/action-remove-labels@v1
if: fromJSON(steps.check_build.outputs.data).total_count == 0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: |
deploy:athena-test3
- name: Check if latest push had successful build
if: fromJSON(steps.check_build.outputs.data).total_count == 0
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '### ❌ Unable to deploy to test server ❌\nThe docker build needs to run through before deploying.'
})
core.setFailed('The build needs to run through first. Please wait for the build to finish and then try again.')
# Compute the tag to use for the docker image
compute-tag:
needs: [ check-build-status ]
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.compute-tag.outputs.result }}
steps:
- name: Compute Tag
uses: actions/github-script@v6
id: compute-tag
with:
result-encoding: string
script: |
if (context.eventName === "pull_request") {
return "pr-" + context.issue.number;
}
if (context.eventName === "release") {
return "latest";
}
if (context.eventName === "push") {
if (context.ref.startsWith("refs/tags/")) {
return context.ref;
}
if (context.ref === "refs/heads/develop") {
return "develop";
}
}
return "FALSE";
# Run pre-deployment steps
pre-deployment:
needs: [ compute-tag ]
runs-on: ubuntu-latest
steps:
- uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: |
deploy:athena-test3
- name: Check "lock:athena-test3" label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const opts = github.rest.issues.listForRepo.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['lock:athena-test3']
})
const issues = await github.paginate(opts)
if (issues.length == 1 && (!context.issue || issues[0].number != context.issue.number)) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### ❌ Unable to deploy to test server ❌\nAthena Testserver is already in use by PR #${issues[0].number}.`
})
core.setFailed(`Athena Testserver is already in use by PR #${issues[0].number}.`);
} else if (issues.length > 1) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '### ❌ Unable to deploy to test server ❌\nAthena Testserver is already in use by multiple PRs. Check PRs with label "lock:pyris-test"!'
})
core.setFailed('Athena Testserver is already in use by multiple PRs. Check PRs with label "lock:athena-test3"!');
} else if (context.issue && context.issue.number) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['lock:athena-test3']
})
}
# Deploy to the test servers
deploy:
needs: [ compute-tag, pre-deployment ]
uses: ./.github/workflows/deploy.yml
with:
docker-tag: ${{ needs.compute-tag.outputs.tag }}
branch-name: ${{ github.event.pull_request.head.ref }}
environment-name: Athena Test Server 3
environment-url: https://athenetest1-03.ase.cit.tum.de/
secrets: inherit
# Check that the build job has run successfully otherwise add an error label
add-error-label:
needs: [ check-build-status, compute-tag, pre-deployment, deploy ]
runs-on: ubuntu-latest
if: ${{ failure() }}
steps:
- name: Add error label
uses: actions-ecosystem/action-add-labels@v1
with:
labels: deployment-error