From 04a1ab0b981ce0d8f1190959316c60da1dfc68ce Mon Sep 17 00:00:00 2001 From: David Leal Date: Fri, 16 Dec 2022 16:52:48 -0600 Subject: [PATCH] feat: improve the Awesome Workflow (#2408) * fix: Awesome Workflow issues Thanks to @tjgurwara99 for the original fix: TheAlgorithms/C#1176 * chore: apply suggestions from code review Co-authored-by: Taj * feat: various improvements * chore: apply suggestions from code review Co-authored-by: Taj --- .github/workflows/awesome_workflow.yml | 57 ++++++++------------------ .github/workflows/codeql.yml | 51 +++++++++++++++++++++++ .github/workflows/codeql_analysis.yml | 48 ---------------------- .github/workflows/gh-pages.yml | 4 +- 4 files changed, 71 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/codeql_analysis.yml diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index d9b405ec2..315629c98 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -1,51 +1,32 @@ name: Awesome CI Workflow - on: [push, pull_request] -# push: -# branches: [ master ] -# pull_request: -# branches: [ master ] +permissions: + contents: write jobs: MainSequence: name: Code Formatter runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 # v2 is broken for git diff - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 - name: requirements run: | - sudo apt -qq -y update - sudo apt -qq install clang-tidy-10 clang-format-10 + sudo apt-get -qq update + sudo apt-get -qq install clang-tidy clang-format # checks are passing with less errors when used with this version. # The default installs v6.0 which did not work out well in my tests - name: Setup Git Specs run: | - git config --global user.name David Leal - git config --global user.email 'Panquesito7@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git config --global user.name github-actions[bot] + git config --global user.email 'github-actions@users.noreply.github.com' - name: Filename Formatter run: | - IFS=$'\n' - for fname in `find . -type f -name '*.cpp' -o -name '*.cc' -o -name '*.h'` - do - echo "${fname}" - new_fname=`echo ${fname} | tr ' ' '_'` - echo " ${new_fname}" - new_fname=`echo ${new_fname} | tr 'A-Z' 'a-z'` - echo " ${new_fname}" - new_fname=`echo ${new_fname} | tr '-' '_'` - echo " ${new_fname}" - new_fname=${new_fname/.cc/.cpp} - echo " ${new_fname}" - if [ ${fname} != ${new_fname} ] - then - echo " ${fname} --> ${new_fname}" - git "mv" "${fname}" ${new_fname} - fi - done - git commit -am "formatting filenames ${GITHUB_SHA::8}" || true - + wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/filename_formatter.sh + chmod +x filename_formatter.sh + ./filename_formatter.sh . .cpp,.hpp - name: Update DIRECTORY.md run: | wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py @@ -53,9 +34,7 @@ jobs: git commit -m "updating DIRECTORY.md" DIRECTORY.md || true - name: Get file changes run: | - git remote -v git branch - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY git diff --diff-filter=dr --name-only origin/master > git_diff.txt echo "Files changed-- `cat git_diff.txt`" - name: Configure for static lint checks @@ -81,10 +60,10 @@ jobs: if not cpp_files: sys.exit(0) - subprocess.run(["clang-tidy-10", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"], + subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"], check=True, text=True, stderr=subprocess.STDOUT) - subprocess.run(["clang-format-10", "-i", "-style=file", *cpp_files], + subprocess.run(["clang-format", "-i", "-style=file", *cpp_files], check=True, text=True, stderr=subprocess.STDOUT) upper_files = [file for file in cpp_files if file != file.lower()] @@ -108,8 +87,8 @@ jobs: - name: Commit and push changes run: | git diff DIRECTORY.md - git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true - git push --force origin HEAD:$GITHUB_REF || true + git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true + git push origin HEAD:$GITHUB_REF || true build: name: Compile checks @@ -119,7 +98,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 with: submodules: true - run: cmake -B ./build -S . diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..c74a015cc --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,51 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: cpp + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + # + # In our case, this would be a CMake build step. + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:cpp" diff --git a/.github/workflows/codeql_analysis.yml b/.github/workflows/codeql_analysis.yml deleted file mode 100644 index aa3ddbd7f..000000000 --- a/.github/workflows/codeql_analysis.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: "CodeQL" -on: [push, pull_request] - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'cpp' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@main - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@main - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@main - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@main diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 881ea1c33..134c04bb1 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -8,7 +8,7 @@ jobs: build: runs-on: macos-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 with: submodules: true - name: Install requirements @@ -19,7 +19,7 @@ jobs: - name: build run: cmake --build build -t doc - name: gh-pages - uses: actions/checkout@master + uses: actions/checkout@v3 with: ref: "gh-pages" clean: false