Skip to content

Commit

Permalink
ci: clean workflow
Browse files Browse the repository at this point in the history
- add clean workflow
- remove msvc-analysis workflow
- minor changes
  • Loading branch information
ctapmex committed Aug 8, 2024
1 parent 1087d6e commit c760d96
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 99 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/clean_workflow.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 19 additions & 7 deletions .github/workflows/farcolorer-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}


92 changes: 0 additions & 92 deletions .github/workflows/msvc-analysis.yml

This file was deleted.

73 changes: 73 additions & 0 deletions .github/workflows/prebuild.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions ci/clean_packages/main.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 3 additions & 0 deletions ci/clean_packages/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fastcore==1.6.3
ghapi==1.0.5
packaging==24.1

0 comments on commit c760d96

Please sign in to comment.