Build and Push Docker Image Workflow #220
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: OpenAPI | |
on: | |
pull_request: | |
types: [opened, synchronize, labeled, reopened] | |
paths: | |
- 'server/application-server/**' | |
- '.github/workflows/generate-intelligence-service-client.yml' | |
push: | |
paths: | |
- 'server/intelligence-service/openapi.yaml' | |
- 'server/application-server/src/main/java/de/tum/in/www1/hephaestus/intelligenceservice/**' | |
branches: [develop] | |
workflow_dispatch: | |
jobs: | |
generate-api-client: | |
name: Verify API Specs and Client of the Intelligence Service (add autocommit-openapi label to PR to auto-commit changes) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.12 | |
- name: Install dependencies | |
run: npm install | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
virtualenvs-path: .venv | |
installer-parallel: true | |
- name: Load cached venv | |
id: cached-poetry-dependencies | |
uses: actions/cache@v4 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Install Python dependencies | |
working-directory: server/intelligence-service | |
run: poetry lock --no-update && poetry install --no-interaction --no-root | |
- name: Generate API client for the application server | |
working-directory: server/intelligence-service | |
run: poetry run npm run generate:api:intelligence-service | |
- name: Check for changes in the API | |
id: check_changes | |
run: | | |
echo "Checking for changes in the API client directory..." | |
git add . | |
if git diff --cached --quiet; then | |
echo "No changes detected in the API client directory." | |
echo "NO_CHANGES_DETECTED=true" >> $GITHUB_ENV | |
else | |
echo "Changes detected in the API client directory." | |
echo "NO_CHANGES_DETECTED=false" >> $GITHUB_ENV | |
exit 1 | |
fi | |
- name: Commit files | |
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }} | |
run: | | |
echo "Committing and pushing changes..." | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git commit -a -m "chore: update API specs and client" | |
- name: Push changes | |
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }} | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GH_PAT }} | |
branch: ${{ github.event.pull_request.head.ref }} | |
- name: Remove autocommit-openapi label | |
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }} | |
run: | | |
echo "Removing the autocommit-openapi label..." | |
curl --silent --fail-with-body -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi |