diff --git a/.github/workflows/check-modified-files-as-step/action.yaml b/.github/workflows/check-modified-files-as-step/action.yaml new file mode 100644 index 000000000..12d4b8060 --- /dev/null +++ b/.github/workflows/check-modified-files-as-step/action.yaml @@ -0,0 +1,37 @@ +name: Check if a path was modified +description: Reusable action for checking if a file path is modified as a step. It outputs a `changed` variable which can be referenced later. + +inputs: + path: + description: 'Path to check' + required: true + +runs: + using: composite + steps: + ######################################## + # Check to see if files changed + ######################################## + - name: "🔍 Check if $PATH_TO_CHECK is modified in last commit " + env: + PATH_TO_CHECK: ${{ inputs.path }} + shell: bash + run: | + set -eExou pipefail + + echo "=============== list modified files ===============" + git diff --name-only HEAD^ HEAD + + echo "========== check paths of modified files ==========" + git diff --name-only HEAD^ HEAD > files.txt + while IFS= read -r file + do + echo $file + if [[ $file != $PATH_TO_CHECK ]]; then + echo "changed=false" >> $GITHUB_ENV + else + echo "File $file matches $PATH_TO_CHECK" + echo "changed=true" >> $GITHUB_ENV + break + fi + done < files.txt diff --git a/.github/workflows/dashboard.yaml b/.github/workflows/dashboard.yaml new file mode 100644 index 000000000..76d547c44 --- /dev/null +++ b/.github/workflows/dashboard.yaml @@ -0,0 +1,34 @@ +name: Build and push dashboard image +on: + push: + paths: + - dashboard + branches: + - "main" + pull_request: + merge_group: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: "🚀 Building" + run: | + docker build -t ghcr.io/dfinity/dre/ic-management-frontend:$GITHUB_SHA -f dashboard/Dockerfile dashboard + + - name: "🔧 Login to GitHub Container Registry" + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: "📦 Push images to GitHub Container Registry" + if: ${{ startsWith(github.head_ref, 'container') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }} + run: | + docker push ghcr.io/dfinity/dre/ic-management-frontend:$GITHUB_SHA diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 822646e42..b88ef3c99 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -20,6 +20,8 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: "☁️ Setup runner" uses: ./.github/workflows/manage-runner-pre @@ -65,6 +67,35 @@ jobs: if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.head_ref, 'container') || startsWith(github.ref, 'refs/heads/container') || (github.ref == 'refs/heads/main') }} run: bazel query --noshow_progress 'kind("oci_push", ...)' | xargs -I_target bazel run _target -- --tag ${GITHUB_SHA} + ######################################## + # Check if dashboard/* changed to see if + # it also needs to be updated in k8s + ######################################## + - name: "❓ Check if dashboard/* changed in last commit" + id: check + uses: ./.github/workflows/check-modified-files-as-step + with: + path: dashboard/* + + - name: "💲 Setting correct paths to update" + id: paths + shell: bash + run: | + files=( + bases/apps/mainnet-dashboard/statefulset-slack.yaml + bases/apps/mainnet-dashboard/backend/base/deployment.yaml + ) + if [[ $changed == "true" ]]; then + echo "Adding frontend to list of files" + files+=( bases/apps/mainnet-dashboard/frontend/deployment.yaml ) + else + echo "Skipping adding of frontend to list of files" + fi + + echo "Output of this step:" + echo ${files[@]} + echo "files=${files[@]}" >> $GITHUB_ENV + ######################################## # Update k8s deployments ######################################## @@ -74,6 +105,9 @@ jobs: with: gitlab_api_token: ${{ secrets.GITLAB_K8S_API_TOKEN }} + ######################################## + # Deploy to github pages + ######################################## - name: "🚢 Deploy to GitHub Pages" if: ${{ github.ref == 'refs/heads/main' }} run: | diff --git a/.github/workflows/update-k8s-deployments/action.yaml b/.github/workflows/update-k8s-deployments/action.yaml index 51f59ec23..d44729280 100644 --- a/.github/workflows/update-k8s-deployments/action.yaml +++ b/.github/workflows/update-k8s-deployments/action.yaml @@ -16,6 +16,9 @@ runs: run: | set -eExou pipefail + echo "Should change following files:" + echo $files + cd .git # checkout branch @@ -30,7 +33,7 @@ runs: # this regex matches the first group (ie the image name) and uses \1 # called a back-reference to insert the first group matched, the second # part is to match the 40 characters hash that we replace with the $GITHUB_SHA - sed -i "s~\(\([[:alpha:]]\|-\)\+\):[[:alnum:]]\{40\}~\1:${GITHUB_SHA}~g" bases/apps/mainnet-dashboard/statefulset-slack.yaml bases/apps/mainnet-dashboard/backend/base/deployment.yaml bases/apps/mainnet-dashboard/frontend/deployment.yaml + sed -i "s~\(\([[:alpha:]]\|-\)\+\):[[:alnum:]]\{40\}~\1:${GITHUB_SHA}~g" $files # commit changes if there are any git add . diff --git a/dashboard/docker-compose.dev.yml b/dashboard/docker-compose.dev.yml index c546d9962..b260032c6 100644 --- a/dashboard/docker-compose.dev.yml +++ b/dashboard/docker-compose.dev.yml @@ -9,12 +9,12 @@ services: dashboard-backend-mainnet: build: context: .. - dockerfile: ic-management-backend/Dockerfile + dockerfile: rs/ic-management-backend/Dockerfile args: BUILDKIT_INLINE_CACHE: 1 slack: build: context: .. - dockerfile: slack-notifications/Dockerfile + dockerfile: rs/slack-notifications/Dockerfile args: BUILDKIT_INLINE_CACHE: 1