Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: Add automatic release action on file change #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this variable does not exist in this repo, isn't it?
Can you point us how to create that secret? Any doc from the action's creator?

66 changes: 66 additions & 0 deletions .github/workflows/sync-lists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2024 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

name: Sync and Release

on:
schedule:
- cron: "0 0 1 * *" # Run once a month
workflow_dispatch:
inputs:
reason:
description: 'Reason'
required: false
default: 'Manual trigger'

permissions:
contents: write

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: actions/checkout@v3
uses: actions/checkout@v4


- 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this diffing the entire repo files? Shouldn't we diff only the files in counter-robots/data?

continue-on-error: true

- name: Commit if changes detected
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using an action instead? WDYT?

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)
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major: I believe you are missing to create the tag as well or am I missing something?


- name: Create and push tag
if: env.changes_detected == 'true'
run: |
git tag "v${{ env.new_version }}" -a "release: ${{ env.new_version }}"
git push origin "v${{ env.new_version }}"
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include *.rst
include *.sh
include LICENSE
include pytest.ini
include bump_version.py
prune docs/_build
recursive-include .github/workflows *.yml
recursive-include counter_robots *.po *.pot *.mo
Expand Down
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test it, but ChatGPT simply proposed to do it in the actions:

    - name: Get current year and month
      id: date
      run: echo "year_month=$(date +'%Y.%m')" >> $GITHUB_ENV

    - name: Update __version__ in __init__.py
      run: |
        sed -i "s/^__version__ = .*/__version__ = \"${{ env.year_month }}\"/" path/to/your/__init__.py


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)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down