Skip to content

Commit

Permalink
Merge pull request #107 from esg-epfl-apc/archives-tool-githubaction-…
Browse files Browse the repository at this point in the history
…archives-list-update

Github action for updating archives list
  • Loading branch information
volodymyrss authored Oct 16, 2024
2 parents 4543470 + 3e0dcc7 commit 4f928d7
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/update-archives-list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: update-archives-list-pr
run-name: Updating archives list and tool version
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
jobs:
run-archive-script:
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v4

- name: install python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: install pyvo and required dependencies
run: |
python -m ensurepip --upgrade
pip install astropy
pip install requests
pip install pyvo
- name: create temp PR branch
run: |
DATE=$(date +'%Y%m%d')
BRANCH_NAME="archives-update-pr-${DATE}"
git checkout -b $BRANCH_NAME
git push origin $BRANCH_NAME
git push --set-upstream origin archives-update-pr-${DATE}
- name: run archives script
run: |
python fetch_archives.py
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "updated archives file"
git push
- name: List files after script execution
run: ls -la

- name: create pull request
run: |
HAS_COMMITS=$(git rev-list --count HEAD ^origin/main)
if [ "$HAS_COMMITS" -gt 0 ]; then
python update_tool_version.py
git add .
git commit -m "updated tool version"
git push
DATE=$(date +'%Y%m%d')
BRANCH_NAME="archives-update-pr-${DATE}"
gh pr create -B main -H $BRANCH_NAME --title 'Archives list update' --body 'Automated pull request for archives list update'
else
echo "No modifications in available archives"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions fetch_archives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pyvo


def fetch_archives():
archive_list = pyvo.registry.search(servicetype="tap")

with open('tools/archives/pyvo_integration/tool-data/astronomical_archives_gen.loc', 'w') as f, open('tools/archives/pyvo_integration/tool-data/astronomical_archives_gen.loc.sample', 'w') as f1:

table_description = '#Table used for listing astronomical archives TAP service urls\n'
column_description = '#<id>\t<display_name>\t<value>\n'

f.write(table_description)
f.write(column_description)

f1.write(table_description)
f1.write(column_description)

archive = archive_list[0]
archive_name = archive.res_title
access_url = archive.access_url

f1.write(f'0\t{archive_name}\t{access_url}\n')

for i, archive in enumerate(archive_list):
try:
archive_name = archive.res_title
access_url = archive.access_url
f.write(f'{i}\t{archive_name}\t{access_url}\n')
except Exception as e:
pass


if __name__ == '__main__':
fetch_archives()

33 changes: 33 additions & 0 deletions update_tool_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import re

def increment_version(file_path):
version_pattern = r'(\d+\.\d+\.)(\d+)'

try:
with open(file_path, 'r') as file:
lines = file.readlines()

first_line = lines[0]
match = re.search(version_pattern, first_line)

if match:
base_version = match.group(1)
last_number = int(match.group(2))
new_last_number = last_number + 1
new_version = f"{base_version}{new_last_number}"
updated_line = first_line.replace(match.group(0), new_version)
lines[0] = updated_line

with open(file_path, 'w') as file:
file.writelines(lines)

except FileNotFoundError:
print(f"No archives file at: {file_path}")
except Exception as e:
print(f"Error while updating version: {e}")


if __name__ == "__main__":
file_path = 'tools/archives/pyvo_integration/astronomical_archives.xml'

increment_version(file_path)

0 comments on commit 4f928d7

Please sign in to comment.