diff --git a/.github/workflows/clean_workflow.yml b/.github/workflows/clean_workflow.yml new file mode 100644 index 0000000..1c1014a --- /dev/null +++ b/.github/workflows/clean_workflow.yml @@ -0,0 +1,46 @@ +name: Delete old artifacts +on: + workflow_dispatch: + schedule: + - cron: '0 0 1 * *' +# Run monthly, at 00:00 on the 1st day of month. + +jobs: + clean_wf_runs: + runs-on: ubuntu-latest + permissions: + actions: write + contents: read + steps: + - name: Delete workflow runs + uses: Mattraks/delete-workflow-runs@v2 + with: + token: ${{ github.token }} + repository: ${{ github.repository }} + retain_days: 30 + keep_minimum_runs: 6 + check_pullrequest_exist: true + + clean_packages: + runs-on: ubuntu-latest + steps: + - name: checkout repo content + uses: actions/checkout@v4 + + - name: setup python + uses: actions/setup-python@v5 + + - name: install python packages + working-directory: ./ci/clean_packages + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: execute clean script + working-directory: ./ci/clean_packages + env: + ORG_NAME: colorer + PACKAGE_MASK: ^farcolorer_.* + PACKAGE_TYPE: nuget + GITHUB_TOKEN: ${{ secrets.PACKAGES_GITHUB_TOKEN }} + run: python main.py diff --git a/.github/workflows/farcolorer-ci.yml b/.github/workflows/farcolorer-ci.yml index e706ec5..b46fd9b 100644 --- a/.github/workflows/farcolorer-ci.yml +++ b/.github/workflows/farcolorer-ci.yml @@ -6,8 +6,18 @@ on: branches: - master paths-ignore: - - 'version4far.txt' + - '.github/workflows/clean_workflow.yml' + - '.github/workflows/prebuild.yml' + - '.github/workflows/farcolorer-release.yml' + - 'ci/**' + - 'docs/**' + - 'scripts/**' + - '.clang-format' + - '.gitignore' + - 'CMakePresets.json' + - 'LICENSE' - 'README.md' + - 'version4far.txt' pull_request: branches: - master @@ -58,14 +68,17 @@ jobs: -username "${{ secrets.PACKAGES_GITHUB_USER }}" -password "${{ secrets.PACKAGES_GITHUB_TOKEN }}" - - name: Create Build forlder - run: cmake -E make_directory ${{runner.workspace}}/build + - name: Create Build folder + run: mkdir -p _build + + - name: Get number of CPU cores + uses: SimenB/github-actions-cpu-cores@v2 + id: cpu-cores - name: Configure CMake shell: bash - working-directory: ${{runner.workspace}}/build run: > - cmake $GITHUB_WORKSPACE -G "Ninja" + cmake -S . -B _build -G "Ninja" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCOLORER_BUILD_ARCH=${{ matrix.build }} -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/external/colorer/external/vcpkg/scripts/buildsystems/vcpkg.cmake @@ -75,8 +88,7 @@ jobs: -DVCPKG_FEATURE_FLAGS=manifests,versions - name: Build - working-directory: ${{runner.workspace}}/build shell: bash - run: cmake --build . --config $BUILD_TYPE + run: cmake --build _build --config $BUILD_TYPE -j ${{ steps.cpu-cores.outputs.count }} diff --git a/.github/workflows/msvc-analysis.yml b/.github/workflows/msvc-analysis.yml deleted file mode 100644 index 0c66298..0000000 --- a/.github/workflows/msvc-analysis.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Microsoft C++ Code Analysis - -on: - workflow_dispatch: - pull_request: - branches: [ master ] - schedule: - - cron: '00 22 * * 5' - -env: - # Path to the CMake build directory. - BUILD_TYPE: Release - X_VCPKG_NUGET_ID_PREFIX: 'farcolorer' - VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite' - -jobs: - analyze: - name: Analyze - runs-on: windows-latest - - steps: - - name: Checkout source - uses: actions/checkout@v3 - with: - submodules: recursive - # fetch all for vcpkg versions functionality - fetch-depth: 0 - - - name: Install vcpkg - run: | - cd external\colorer\external\vcpkg - .\bootstrap-vcpkg.bat - - - name: Add C++ build tools to PATH - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: amd64 - - - name: Setup NuGet Credentials for cache - shell: bash - run: > - `$VCPKG_INSTALLATION_ROOT/vcpkg fetch nuget | tail -n 1` - sources add - -source "https://nuget.pkg.github.com/colorer/index.json" - -storepasswordincleartext - -name "GitHub" - -username "${{ secrets.PACKAGES_GITHUB_USER }}" - -password "${{ secrets.PACKAGES_GITHUB_TOKEN }}" - - - name: Create Build forlder - run: cmake -E make_directory ${{runner.workspace}}/build - - - name: Configure CMake - shell: bash - working-directory: ${{runner.workspace}}/build - run: > - cmake $GITHUB_WORKSPACE -G "Ninja" - -DCMAKE_BUILD_TYPE=$BUILD_TYPE - -DCOLORER_BUILD_ARCH=x64 - -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/external/colorer/external/vcpkg/scripts/buildsystems/vcpkg.cmake - -DVCPKG_TARGET_TRIPLET=x64-windows-static-rel - -DVCPKG_OVERLAY_PORTS=$GITHUB_WORKSPACE/external/colorer/external/vcpkg-ports - -DVCPKG_OVERLAY_TRIPLETS=$GITHUB_WORKSPACE/external/colorer/external/vcpkg-triplets - -DVCPKG_FEATURE_FLAGS=manifests,versions - - - # Build is not required unless generated source files are used - # - name: Build CMake - # run: cmake --build ${{ env.build }} - - - name: Initialize MSVC Code Analysis - uses: microsoft/msvc-code-analysis-action@v0.1.1 - # Provide a unique ID to access the sarif output path - id: run-analysis - with: - cmakeBuildDirectory: ${{runner.workspace}}/build - # Ruleset file that will determine what checks will be run - ruleset: NativeRecommendedRules.ruleset - ignoredPaths: ${{ github.workspace }}/external - - # Upload SARIF file to GitHub Code Scanning Alerts - - name: Upload SARIF to GitHub - uses: github/codeql-action/upload-sarif@v1 - with: - sarif_file: ${{ steps.run-analysis.outputs.sarif }} - - # Upload SARIF file as an Artifact to download and view - # - name: Upload SARIF as an Artifact - # uses: actions/upload-artifact@v3 - # with: - # name: sarif-file - # path: ${{ steps.run-analysis.outputs.sarif }} diff --git a/.github/workflows/prebuild.yml b/.github/workflows/prebuild.yml new file mode 100644 index 0000000..1120319 --- /dev/null +++ b/.github/workflows/prebuild.yml @@ -0,0 +1,73 @@ +name: "Prebuild vcpkg" + +on: + workflow_dispatch: + schedule: + - cron: '0 1 * * 1,3,5' + +env: + BUILD_TYPE: Release + X_VCPKG_NUGET_ID_PREFIX: 'colorer' + VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite' + +jobs: + windows-vc: + runs-on: windows-2022 + + strategy: + fail-fast: false + matrix: + build: [ x64, x86 , ARM64 ] + include: + - { build: x64, arch: amd64, triplet: x64-windows-static-rel, } + - { build: x86, arch: amd64_x86, triplet: x86-windows-static-rel, } + - { build: ARM64, arch: amd64_arm64, triplet: arm64-windows-static-rel, } + + name: windows-${{ matrix.arch }} + + steps: + - name: Checkout source + uses: actions/checkout@v4 + with: + submodules: recursive + # fetch all for vcpkg versions functionality + fetch-depth: 0 + + - name: Install vcpkg + run: | + cd external\vcpkg + .\bootstrap-vcpkg.bat + + - name: Add C++ build tools to PATH + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + + - name: Setup NuGet Credentials for vpckg cache + shell: bash + run: > + `$GITHUB_WORKSPACE/external/vcpkg/vcpkg fetch nuget | tail -n 1` + sources add + -source "https://nuget.pkg.github.com/colorer/index.json" + -storepasswordincleartext + -name "GitHub" + -username "${{ secrets.PACKAGES_GITHUB_USER }}" + -password "${{ secrets.PACKAGES_GITHUB_TOKEN }}" + + - name: Create Build folder + run: mkdir -p _build + + - name: Configure CMake + shell: bash + # add -DVCPKG_INSTALL_OPTIONS="--debug" for debug output + run: > + cmake -S . -B _build -G "Ninja" + -DCMAKE_BUILD_TYPE=$BUILD_TYPE + -DCOLORER_BUILD_ARCH=${{ matrix.build }} + -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/external/colorer/external/vcpkg/scripts/buildsystems/vcpkg.cmake + -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} + -DVCPKG_OVERLAY_PORTS=$GITHUB_WORKSPACE/external/colorer/external/vcpkg-ports + -DVCPKG_OVERLAY_TRIPLETS=$GITHUB_WORKSPACE/external/colorer/external/vcpkg-triplets + -DVCPKG_FEATURE_FLAGS=manifests,versions + +# dependencies are being built at the configuration stage \ No newline at end of file diff --git a/ci/clean_packages/main.py b/ci/clean_packages/main.py new file mode 100644 index 0000000..9ef0e50 --- /dev/null +++ b/ci/clean_packages/main.py @@ -0,0 +1,52 @@ +# Script for cleaning old versions of packages in GitHub Packages +# Author: https://github.com/ctapmex + +from ghapi.all import GhApi +from ghapi.page import paged +import os +import re + + +def get_version_for_remove(package_versions): + sorted_version = sorted(package_versions, key=lambda d: d['created_at'], reverse=True) + # remove from list actual version + del sorted_version[0] + return sorted_version + + +org_name = os.getenv('ORG_NAME', None) +package_mask = os.getenv('PACKAGE_MASK', None) +package_type = os.getenv('PACKAGE_TYPE', None) +github_token = os.getenv('GITHUB_TOKEN', None) + +if not org_name or not package_type or not package_mask or not github_token: + raise BaseException("not all significant parameters are set") + +api = GhApi(token=github_token) + +package_pages = paged(api.packages.list_packages_for_organization, org=org_name, + package_type=package_type, visibility=None, per_page=100) + +print("search packages") +for package_page in package_pages: + for package in package_page: + if re.search(package_mask, package['name']): + print("found package - ", package['name']) + package_version = [] + version_pages = paged(api.packages.get_all_package_versions_for_package_owned_by_org, org=org_name, + package_name=package['name'], package_type=package['package_type'], state='active', + per_page=100) + for version_page in version_pages: + for version in version_page: + vp = {'version_id': version['id'], 'created_at': version['created_at']} + package_version.append(vp) + + version_for_del = get_version_for_remove(package_version) + print("count of versions of the package to delete - ", len(version_for_del)) + for version in version_for_del: + print("delete id=", version['version_id']) + api.packages.delete_package_version_for_org(org=org_name, package_name=package['name'], + package_type=package['package_type'], + package_version_id=version['version_id']) + +print("finish") diff --git a/ci/clean_packages/requirements.txt b/ci/clean_packages/requirements.txt new file mode 100644 index 0000000..10a21fb --- /dev/null +++ b/ci/clean_packages/requirements.txt @@ -0,0 +1,3 @@ +fastcore==1.6.3 +ghapi==1.0.5 +packaging==24.1