chore: update GitHub Actions to use latest versions of actions and No… #33
This file contains hidden or 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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| DOCKER_APP_IMAGE_NAME: 'ghcr.io/hasadna/open-bus-backend/open-bus-backend' | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| HASADNA_K8S_DEPLOY_KEY: ${{ secrets.HASADNA_K8S_DEPLOY_KEY }} | |
| jobs: | |
| ci: | |
| name: CI | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Check environment variables and Docker login | |
| run: | | |
| for var in DOCKER_APP_IMAGE_NAME GITHUB_TOKEN HASADNA_K8S_DEPLOY_KEY; do | |
| if [ -z "${!var}" ]; then | |
| echo "Missing required environment variable: $var" | |
| exit 1 | |
| fi | |
| done | |
| echo "${GITHUB_TOKEN}" | docker login ghcr.io -u hasadna --password-stdin | |
| - name: Cache node modules | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-npm- | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Cache Docker layers | |
| uses: actions/cache@v5 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Build, tag, push Docker image and deploy | |
| run: | | |
| if docker pull "${DOCKER_APP_IMAGE_NAME}:latest"; then | |
| CACHE_FROM_ARG="--cache-from=type=local,src=/tmp/.buildx-cache" | |
| else | |
| CACHE_FROM_ARG="" | |
| fi | |
| docker build $CACHE_FROM_ARG --build-arg VERSION=${GITHUB_SHA} -t app . | |
| docker tag app "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" | |
| docker push "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" | |
| if [ "${GITHUB_REF}" == "refs/heads/main" ]; then | |
| docker tag app "${DOCKER_APP_IMAGE_NAME}:latest" | |
| docker push "${DOCKER_APP_IMAGE_NAME}:latest" | |
| if ! git log -1 --pretty=format:"%s" | grep -- --no-deploy; then | |
| cd `mktemp -d` | |
| echo "${HASADNA_K8S_DEPLOY_KEY}" > hasadna_k8s_deploy_key | |
| chmod 400 hasadna_k8s_deploy_key | |
| export GIT_SSH_COMMAND="ssh -i `pwd`/hasadna_k8s_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" | |
| git clone git@github.com:hasadna/hasadna-k8s.git | |
| cd hasadna-k8s | |
| python update_yaml.py '{"backendImage":"'"${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}"'"}' apps/openbus/values-hasadna-auto-updated.yaml | |
| git config --global user.name "Open Bus Backend CI" | |
| git config --global user.email "open-bus-backend-ci@localhost" | |
| git add apps/openbus/values-hasadna-auto-updated.yaml && git commit -m "automatic update of open bus backend" | |
| git push origin master | |
| fi | |
| fi |