-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 }} | ||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
continue-on-error: true | ||||||
|
||||||
- name: Commit if changes detected | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import datetime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
|
||
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) |
There was a problem hiding this comment.
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?