From 9d64fcf68f03a218303a18cab92d34596ea65b30 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 19 Feb 2024 22:41:09 +0600 Subject: [PATCH 1/4] housekeeping --- .github/workflows/housekeeping.yml | 40 +++++++++++++++++ .github/workflows/publish_housekeeping.yml | 50 ++++++++++++++++++++++ docker/Dockerfile.housekeeping | 7 +++ 3 files changed, 97 insertions(+) create mode 100644 .github/workflows/housekeeping.yml create mode 100644 .github/workflows/publish_housekeeping.yml create mode 100644 docker/Dockerfile.housekeeping diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml new file mode 100644 index 0000000000..dbdaa38414 --- /dev/null +++ b/.github/workflows/housekeeping.yml @@ -0,0 +1,40 @@ +name: Housekeeping Checks + +on: + # allows us to run workflows manually + workflow_dispatch: + pull_request: + branches: + - develop + +jobs: + Housekeeping: + runs-on: ubuntu-latest + container: + image: ghcr.io/cyclus/cyclus-ci-ubuntu-22.04-housekeeping:latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup environment + run: | + echo "REPO_SLUG=${GITHUB_REPOSITORY}" >> $GITHUB_ENV + echo "PULL_REQUEST=$(echo $GITHUB_REF | cut -d"/" -f3)" >> $GITHUB_ENV + mkdir /root/build_dir + ln -s $GITHUB_WORKSPACE /root/build_dir/cyclus + + - name: Housekeeping + run: | + cd $GITHUB_WORKSPACE + git config --global --add safe.directory /__w/cyclus/cyclus + find src/ \( -name "*.hpp" -o -name "*.cpp" -o -name "*.hh" -o -name "*.cc" -o -name "*.h" \) \ + -exec clang-format -style=file -i {} \; + clang_diffs=`git status --porcelain` + if [ -z "${clang_diffs}" ]; then + echo -e "\033[32mStyle guide checker passed!\033[0m" + else + echo -e "\033[1;31mERROR: Style guide checker failed. Please run clang-format.\033[0m" + echo -e "\033[33mclang_diffs: ${clang_diffs}\033[0m" + git diff + exit 1 + fi diff --git a/.github/workflows/publish_housekeeping.yml b/.github/workflows/publish_housekeeping.yml new file mode 100644 index 0000000000..f845a2a540 --- /dev/null +++ b/.github/workflows/publish_housekeeping.yml @@ -0,0 +1,50 @@ +name: Publish Housekeeping Image + +on: + pull_request: + paths: + - ".github/workflows/publish_housekeeping.yml" + - "docker/Dockerfile.housekeeping" + +jobs: + build-for-release: + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + + name: Publish Housekeeping + steps: + - name: Tag as ci-image-cache + run: | + echo "TAG=ci-image-cache" >> "$GITHUB_ENV" + + - name: Tag as Latest + if: ${{ github.repository_owner == 'cyclus' }} + run: | + echo "TAG=latest" >> "$GITHUB_ENV" + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout Cyclus + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and Push Housekeeping + uses: docker/build-push-action@v5 + with: + cache-from: type=registry,ref=ghcr.io/cyclus/cyclus-ci-ubuntu-22.04-housekeeping:ci-layer-cache + file: docker/Dockerfile.housekeeping + push: true + tags: ghcr.io/cyclus/cyclus-ci-ubuntu-22.04-housekeeping:${{ env.TAG }} + build-args: | + UBUNTU_VERSION=22.04 + TAG=${{ env.TAG }} + OWNER=${{ github.repository_owner }} diff --git a/docker/Dockerfile.housekeeping b/docker/Dockerfile.housekeeping new file mode 100644 index 0000000000..43b5f10789 --- /dev/null +++ b/docker/Dockerfile.housekeeping @@ -0,0 +1,7 @@ +ARG UBUNTU_VERSION=22.04 +ARG OWNER=cyclus +ARG TAG=latest +FROM ghcr.io/${OWNER}/cyclus-ci-ubuntu-${UBUNTU_VERSION}:$TAG + +RUN pip install sphinx; \ + apt-get -y install clang-format From e7c8cdacfc81684170f76fcf1d0387a4d6d9a16a Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 19 Feb 2024 23:13:40 +0600 Subject: [PATCH 2/4] housekeeping --- .github/workflows/housekeeping.yml | 8 ++-- .github/workflows/publish_housekeeping.yml | 50 ---------------------- docker/Dockerfile.housekeeping | 7 --- 3 files changed, 4 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/publish_housekeeping.yml delete mode 100644 docker/Dockerfile.housekeeping diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml index dbdaa38414..781d1ef17d 100644 --- a/.github/workflows/housekeeping.yml +++ b/.github/workflows/housekeeping.yml @@ -10,18 +10,18 @@ on: jobs: Housekeeping: runs-on: ubuntu-latest - container: - image: ghcr.io/cyclus/cyclus-ci-ubuntu-22.04-housekeeping:latest steps: - name: Checkout repository uses: actions/checkout@v3 + - name: Set up Dependencies + run: | + apt-get install -y clang-format + - name: Setup environment run: | echo "REPO_SLUG=${GITHUB_REPOSITORY}" >> $GITHUB_ENV echo "PULL_REQUEST=$(echo $GITHUB_REF | cut -d"/" -f3)" >> $GITHUB_ENV - mkdir /root/build_dir - ln -s $GITHUB_WORKSPACE /root/build_dir/cyclus - name: Housekeeping run: | diff --git a/.github/workflows/publish_housekeeping.yml b/.github/workflows/publish_housekeeping.yml deleted file mode 100644 index f845a2a540..0000000000 --- a/.github/workflows/publish_housekeeping.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Publish Housekeeping Image - -on: - pull_request: - paths: - - ".github/workflows/publish_housekeeping.yml" - - "docker/Dockerfile.housekeeping" - -jobs: - build-for-release: - runs-on: ubuntu-22.04 - permissions: - contents: read - packages: write - - name: Publish Housekeeping - steps: - - name: Tag as ci-image-cache - run: | - echo "TAG=ci-image-cache" >> "$GITHUB_ENV" - - - name: Tag as Latest - if: ${{ github.repository_owner == 'cyclus' }} - run: | - echo "TAG=latest" >> "$GITHUB_ENV" - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Checkout Cyclus - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and Push Housekeeping - uses: docker/build-push-action@v5 - with: - cache-from: type=registry,ref=ghcr.io/cyclus/cyclus-ci-ubuntu-22.04-housekeeping:ci-layer-cache - file: docker/Dockerfile.housekeeping - push: true - tags: ghcr.io/cyclus/cyclus-ci-ubuntu-22.04-housekeeping:${{ env.TAG }} - build-args: | - UBUNTU_VERSION=22.04 - TAG=${{ env.TAG }} - OWNER=${{ github.repository_owner }} diff --git a/docker/Dockerfile.housekeeping b/docker/Dockerfile.housekeeping deleted file mode 100644 index 43b5f10789..0000000000 --- a/docker/Dockerfile.housekeeping +++ /dev/null @@ -1,7 +0,0 @@ -ARG UBUNTU_VERSION=22.04 -ARG OWNER=cyclus -ARG TAG=latest -FROM ghcr.io/${OWNER}/cyclus-ci-ubuntu-${UBUNTU_VERSION}:$TAG - -RUN pip install sphinx; \ - apt-get -y install clang-format From 3f406710a8559682ce0f5149bd441aa62d292390 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 19 Feb 2024 23:26:46 +0600 Subject: [PATCH 3/4] Add Housekeeping to Check Code Style with clang-format --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9dfd7728f6..b0936a05d2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -27,6 +27,7 @@ Since last release * Adds support for Cython3 (#1636) * Adds TotalInvTracker, which allows an inventory cap to be set for multiple resource buffers, and is now required for material buy policy (#1646) * AddMutalReqs and AddReciepe functions and exclusive bids in python API of DRE (#1584) +* Add Housekeeping to Check Code Style with `clang-format` (#1674) **Changed:** From a00effac72a4a4ef9e8b943468b14660be7e6769 Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Mon, 19 Feb 2024 23:38:03 +0600 Subject: [PATCH 4/4] housekeeping --- .github/workflows/housekeeping.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml index 781d1ef17d..96632a4561 100644 --- a/.github/workflows/housekeeping.yml +++ b/.github/workflows/housekeeping.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Dependencies run: | - apt-get install -y clang-format + sudo apt-get install -y clang-format - name: Setup environment run: |