ci: rename lint and test workflow and add submodule update job #16
Workflow file for this run
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: lint-and-test | |
on: | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
sanitize-branch-name: | |
runs-on: ubuntu-latest | |
outputs: | |
sanitized_ref: ${{ steps.sanitize.outputs.sanitized_ref }} | |
steps: | |
- name: sanitize-branch-name | |
id: sanitize | |
run: | | |
SANITIZED_REF=$(echo "${GITHUB_HEAD_REF}" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9' '-') | |
SANITIZED_REF=${SANITIZED_REF#-} | |
SANITIZED_REF=${SANITIZED_REF%-} | |
SANITIZED_REF=${SANITIZED_REF:0:63} | |
if [[ -z "$SANITIZED_REF" || "$SANITIZED_REF" =~ ^-+$ ]]; then | |
SANITIZED_REF="tmp-branch" | |
fi | |
echo "::set-output name=sanitized_ref::${SANITIZED_REF}" | |
shell: bash | |
env: | |
GITHUB_HEAD_REF: ${{ github.head_ref }} | |
update-submodules: | |
name: update-submodules | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
submodules: false | |
- name: update-submodules | |
id: update-submodules | |
run: | | |
git config --global url."https://github.com/".insteadOf "[email protected]:" | |
git submodule sync --recursive | |
git submodule update --init --remote --recursive | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Submodules have new commits. Committing and pushing..." | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git commit -am "chore: update submodules to latest main" | |
git push | |
else | |
echo "No submodule changes." | |
fi | |
# TODO: check if checkout make a checkout of the latest commit of the PR | |
BuildAndLint: | |
name: Build and Lint | |
runs-on: ubuntu-latest | |
needs: [sanitize-branch-name, update-submodules] | |
strategy: | |
fail-fast: true | |
matrix: | |
service: [ "admin-backend", "document-extractor", "rag-backend"] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
repository: stackitcloud/rag-template | |
submodules: true | |
- name: Set Docker Image Name | |
run: | | |
echo "IMAGE_NAME=${{ matrix.service }}:${{ needs.sanitize-branch-name.outputs.sanitized_ref }}-${{ github.run_number }}" >> $GITHUB_ENV | |
shell: bash | |
- name: Build lint image | |
run: | | |
docker build -t $IMAGE_NAME --build-arg dev=1 --build-arg TAG=debug -f ${{ matrix.service }}/Dockerfile . | |
- name: Generate lint report | |
run: | | |
docker run --rm --entrypoint make "$IMAGE_NAME" lint | |
- name: Run tests | |
run: | | |
docker run --rm --entrypoint make "$IMAGE_NAME" test |