Skip to content

Commit bff4c41

Browse files
committed
Add initial structure for action
1 parent 312ef21 commit bff4c41

File tree

7 files changed

+187
-6
lines changed

7 files changed

+187
-6
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Integration Test
2+
on: [push]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@main
8+
- name: Self test
9+
id: selftest
10+
11+
# Put your action repo here
12+
uses: goanpeca/action-test@main
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
with:
16+
source-repo: "pandas-dev/pandas"
17+
source-folder: "pandas/web/pandas/"
18+
source-ref: "main"
19+
translations-repo: "Scientific-Python-Translations/pandas-translations"
20+
translations-folder: "pandas-translations/content/en/"
21+
translations-ref: "main"
22+
23+
- name: Check outputs
24+
run: |
25+
test "${{ steps.selftest.outputs.todo }}" == "Hello world"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,4 @@ cython_debug/
169169

170170
# PyPI configuration file
171171
.pypirc
172+
.DS_Store

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.11-slim-buster
2+
3+
WORKDIR /usr/src/app
4+
5+
RUN apt-get update && \
6+
apt-get upgrade -y && \
7+
apt-get install -y git && \
8+
apt-get install -y rsync
9+
10+
RUN pip install requests pygithub
11+
12+
COPY . .
13+
14+
CMD ["python", "main.py"]
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
MIT License
21

3-
Copyright (c) 2025 Scientific Python Translations
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2023 Quansight, Inc. and contributors
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +10,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
910
copies of the Software, and to permit persons to whom the Software is
1011
furnished to do so, subject to the following conditions:
1112

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
1415

1516
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1617
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1718
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1819
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1920
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# content-sync
2+
23
A Github action to sync translatable content
4+
5+
This is a work in progress!

action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Update Language Source"
2+
description: "Update Source files for the scientific python project"
3+
author: "@goanpeca"
4+
inputs:
5+
source-repo:
6+
description: "Source repository"
7+
required: true
8+
source-folder:
9+
description: "Source folder"
10+
default: ""
11+
source-ref:
12+
description: "Source reference"
13+
default: "main"
14+
translations-repo:
15+
description: "Translations repository"
16+
default: ""
17+
translations-folder:
18+
description: "Translations folder"
19+
default: ""
20+
translations-ref:
21+
description: "Translations reference"
22+
default: "main"
23+
outputs:
24+
todo:
25+
description: "TODO"
26+
runs:
27+
using: "docker"
28+
image: "Dockerfile"

main.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import os
2+
from datetime import datetime
3+
from subprocess import check_output, Popen, PIPE
4+
5+
from github import Github, Auth
6+
7+
8+
# Set the output value by writing to the outputs in the Environment File, mimicking the behavior defined here:
9+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
10+
def set_github_action_output(output_name, output_value):
11+
f = open(os.path.abspath(os.environ["GITHUB_OUTPUT"]), "a")
12+
f.write(f'{output_name}={output_value}')
13+
f.close()
14+
15+
16+
def sync_website_content(token, source_repo, source_folder, source_ref, translations_repo, translations_folder, translations_ref):
17+
cmds = ['git', 'clone', f'https://github.com/{source_repo}.git']
18+
out = check_output(cmds)
19+
print(out)
20+
21+
cmds = ['git', 'clone', f'https://github.com/{translations_repo}.git']
22+
out = check_output(cmds)
23+
print(out)
24+
25+
cmds = ['rsync', '-av', '--delete', source_folder, translations_folder]
26+
out = check_output(cmds)
27+
print(out)
28+
29+
branch_name = datetime.now().strftime('updates-%Y-%m-%d-%H-%M-%S')
30+
os.chdir(translations_repo.split('/')[1])
31+
32+
cmds = ['git', 'checkout', '-b', branch_name]
33+
out = check_output(cmds)
34+
print(out)
35+
36+
cmds = ['git', 'config', '--global', 'user.email', '"actions@github.com"']
37+
out = check_output(cmds)
38+
print(out)
39+
40+
cmds = ['git', 'config', '--global', 'user.name', '"GitHub Actions"']
41+
out = check_output(cmds)
42+
print(out)
43+
44+
cmds = ['git', 'add', '.']
45+
out = check_output(cmds)
46+
print(out)
47+
48+
auth = Auth.Token(token)
49+
g = Github(auth=auth)
50+
repo = g.get_repo(translations_repo)
51+
pulls = repo.get_pulls(state='closed', sort='created', direction='desc')
52+
pr_branch = None
53+
for pr in pulls:
54+
print(pr.number, pr.title)
55+
pr_branch = pr.head.ref
56+
if pr.title == "Update source content":
57+
break
58+
g.close()
59+
60+
# cmds = ['git', 'diff', f'{pr_branch}..{branch_name}']
61+
# out = check_output(cmds)
62+
# print(out)
63+
64+
# git add .
65+
# # Only proceed to commit if there are changes
66+
# if git diff --staged --quiet; then
67+
# echo "No changes to commit."
68+
# echo "CONTENT_CHANGED=false" >> $GITHUB_ENV
69+
# else
70+
# git commit -m "Update website content"
71+
# echo "CONTENT_CHANGED=true" >> $GITHUB_ENV
72+
# git push -u origin ${{ env.BRANCH_NAME }}
73+
# fi
74+
75+
76+
77+
def parse_input():
78+
gh_input = {
79+
'github_token': os.environ["GITHUB_TOKEN"],
80+
'source_repo': os.environ["INPUT_SOURCE-REPO"],
81+
'source_folder': os.environ["INPUT_SOURCE-FOLDER"],
82+
'source_ref': os.environ["INPUT_SOURCE-REF"],
83+
'translations_repo': os.environ["INPUT_TRANSLATIONS-REPO"],
84+
'translations_folder': os.environ["INPUT_TRANSLATIONS-FOLDER"],
85+
'translations_ref': os.environ["INPUT_TRANSLATIONS-REF"],
86+
}
87+
return gh_input
88+
89+
90+
91+
92+
def main():
93+
github_token = os.environ["GITHUB_TOKEN"]
94+
source_repo = os.environ["INPUT_SOURCE-REPO"]
95+
source_folder = os.environ["INPUT_SOURCE-FOLDER"]
96+
source_ref = os.environ["INPUT_SOURCE-REF"]
97+
translations_repo = os.environ["INPUT_TRANSLATIONS-REPO"]
98+
translations_folder = os.environ["INPUT_TRANSLATIONS-FOLDER"]
99+
translations_ref = os.environ["INPUT_TRANSLATIONS-REF"]
100+
101+
# repository = os.environ["GITHUB_REPOSITORY"]
102+
103+
sync_website_content(github_token, source_repo, source_folder, source_ref, translations_repo, translations_folder, translations_ref)
104+
set_github_action_output('todo', 'Hello world')
105+
print("TESTING")
106+
107+
108+
if __name__ == "__main__":
109+
main()

0 commit comments

Comments
 (0)