Skip to content

Commit

Permalink
workflows: Add automatic release action on file change
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 committed Dec 19, 2024
1 parent f751b04 commit 4e1660c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/keepalive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Keepalive

on:
schedule:
- cron: "0 0 1 * *" # Run once a month
workflow_dispatch:

permissions:
contents: write

jobs:

keepalive:
name: Keepalive
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: keepalive

# ensures that crons are not suspended after 60 days
- name: Keepalive check
uses: gautamkrishnar/keepalive-workflow@v1
with:
gh_token: ${{ secrets.INVENIOBOT_PAT }}
46 changes: 46 additions & 0 deletions .github/workflows/sync-lists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Monthly Sync

on:
schedule:
- cron: "0 0 1 * *" # Run once a month
workflow_dispatch:

permissions:
contents: write

jobs:
check-and-update:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run script to update robot and machine lists
run: |
cd scripts/ && python update-lists.py && cd ..
- name: Check for changes
run: |
git diff --quiet || echo "changes_detected=true" >> $GITHUB_ENV
continue-on-error: true

- name: Commit if changes detected
if: env.changes_detected == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./counter_robots/data/machine.txt ./counter_robots/data/robot.txt
git commit -m "Update robots and machines lists"
git push
- name: Update version and push release commit
if: env.changes_detected == 'true'
run: |
NEW_VERSION=python bump_version.py
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add version.py
git commit -m "release: $NEW_VERSION"
git push
36 changes: 36 additions & 0 deletions bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import datetime

current_year = datetime.datetime.now().year
version_file = 'version.py'

with open(version_file, 'r') as file:
try:
content = file.read()
current_version = content.split('__version__ = ')[1][1:-1]
except FileNotFoundError:
current_version = '2018.6'

major, minor = map(int, current_version.split('.'))
new_version = f'{major}.{minor + 1}\n'

with open(version_file, 'w') as file:
file.write(f"""# -*- coding: utf-8 -*-
#
# This file is part of COUNTER-Robots.
# Copyright (C) {current_year} CERN.
#
# COUNTER-Robots is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
\"\"\"Version information for COUNTER-Robots.
This file is imported by ``counter_robots.__init__``,
and parsed by ``setup.py``.
\"\"\"
from __future__ import absolute_import, print_function
__version__ = '{new_version}'
""")

print(new_version)

0 comments on commit 4e1660c

Please sign in to comment.