fix using auto bump versions in docker release #6482
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: nucliadb Writer (py) | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | |
cancel-in-progress: true | |
env: | |
CONTAINER_REGISTRY: eu.gcr.io/${{ secrets.PROJECT_ID }} | |
IMAGE_NAME: writer | |
jobs: | |
# Job to run pre-checks | |
pre-checks: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.9', '3.10', '3.11'] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: 'pip' | |
- name: Install package | |
run: make -C nucliadb/ install-dev | |
- name: Run pre-checks | |
run: make -C nucliadb/ lint-writer | |
# Job to run tests | |
tests: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.11'] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: 'pip' | |
- name: Install the package | |
run: make -C nucliadb/ install-dev | |
- name: Run tests | |
run: | | |
pytest -rfE --cov=nucliadb.writer -s --tb=native -v --cov-report xml --cov-append nucliadb/nucliadb/writer | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.xml | |
flags: writer | |
build: | |
name: Build image and push | |
runs-on: ubuntu-latest | |
needs: tests | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Calculate short sha | |
id: env-vars | |
run: |- | |
HASH=`git rev-parse --short HEAD` | |
BRANCH=${GITHUB_REF##*/} | |
echo "short_sha=$HASH" >> $GITHUB_OUTPUT | |
echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
- name: Setup gcloud CLI | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | |
- name: 'Set up Cloud SDK' | |
uses: 'google-github-actions/setup-gcloud@v1' | |
- name: Configure Docker | |
run: docker login -u oauth2accesstoken -p "$(gcloud auth application-default print-access-token)" https://eu.gcr.io | |
# We need to setup buildx to be able to cache with gha | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=min | |
tags: | | |
${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.env-vars.outputs.short_sha }} | |
${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.env-vars.outputs.branch }} | |
deploy: | |
name: Deploy Helm chart and trigger internal CI | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Calculate short sha | |
id: env-vars | |
run: |- | |
HASH=`git rev-parse --short HEAD` | |
echo "short_sha=$HASH" >> $GITHUB_OUTPUT | |
- name: Set helm package image | |
id: version_step | |
run: |- | |
sed -i.bak "s#IMAGE_TO_REPLACE#$IMAGE_NAME:${{ steps.env-vars.outputs.short_sha }}#" ./charts/nucliadb_writer/values.yaml | |
sed -i.bak "s#CONTAINER_REGISTRY_TO_REPLACE#$CONTAINER_REGISTRY#" ./charts/nucliadb_writer/values.yaml | |
VERSION=`cat VERSION` | |
VERSION_SHA=$VERSION+${{ steps.env-vars.outputs.short_sha }} | |
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/nucliadb_writer/Chart.yaml | |
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "[email protected]" | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.4.0 | |
- name: Push helm package | |
run: |- | |
helm lint charts/nucliadb_writer | |
helm package charts/nucliadb_writer | |
curl --data-binary "@nucliadb_writer-${{ steps.version_step.outputs.version_number }}.tgz" ${{ secrets.HELM_CHART_URL }}/api/charts | |
- name: Repository Dispatch | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
token: ${{ secrets.GH_CICD_PUBLIC }} | |
repository: nuclia/nucliadb_deploy | |
event-type: promote | |
client-payload: '{"component": "nucliadb_writer", "chart-version": "${{ steps.version_step.outputs.version_number }}" }' |