ECDC_update_PR_fork #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ECDC_update_PR_fork | |
# This example workflow is meant to depict steps needed to get the model-output data | |
# from your_organization data GitHub repository and open a pull request to upload data | |
# to european-modelling-hubs/RespiCast-SyndromicIndicators hub-repository | |
# A good starting point for a better understandig of how GitHub actions work | |
# is this: https://docs.github.com/en/actions/quickstart | |
# N.B. | |
# 1. This workflow should be placed under the .github/workflows folder of your FORKED REPO !! | |
# 2. Since the current workflow pulls data directly from the upstream hub (european-modelling-hubs/RespiCast-SyndromicIndicators), | |
# you do not need to sync the forked repo! | |
## TODO: secrets & tokens! | |
# Firts step is to define di events that can trigger this workflow | |
on: | |
workflow_run: | |
workflows: [Generate_RespiCast_Forecasts] | |
types: | |
- completed | |
# Or you can manually trigger the workflow | |
workflow_dispatch: | |
jobs: | |
create_PR_job: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout your forked repository - main branch - | |
# --------------------------------------------------- | |
- name: checkout forked repository | |
uses: actions/checkout@v3 | |
with: | |
ref: 'main' | |
token: ${{secrets.Secret_PUSH_ACCESS_RespiCast}} | |
#this might raise a problem | |
repository: 'ECDC-modelling-team/RespiCast-SyndromicIndicators' | |
path: './destination-repo/' | |
# Step 2: Checkout the model data repository - main branch - | |
# This is the repository where the model output data reside | |
# In this example data repo is https://github.com/your_organization/modeloutput-data-repo | |
# ----------------------------------------------------------------------------- | |
- name: checkout data repository | |
uses: actions/checkout@v3 | |
with: | |
ref: 'main' # the git branch to work on | |
token: ${{ secrets.Secret_PUSH_ACCESS_RespiCast}} #this token will need to be the math modelling one (might need to create a new one) | |
repository: 'EU-ECDC/ECDC-Mathematical-Models' | |
path: './source-repo/' # Relative path under $GITHUB_WORKSPACE to place the repository | |
# Step 3?: Set the default remote repository to use when querying the GitHub API for the locally cloned repository. | |
- run: | | |
cd ./destination-repo/ | |
gh repo set-default european-modelling-hubs/RespiCast-SyndromicIndicators | |
env: | |
GITHUB_TOKEN: ${{ secrets.Secret_PUSH_ACCESS_RespiCast}} #this is probably the correct one (but will need to save the secrets locally) | |
# Step 4: Pull directly from main branch of the upstream repository, | |
# so you do not have to sync and the workflow is not part of the PR | |
- run: | | |
cd ./destination-repo/ | |
git config --global user.name "ECDC-modelling-team" #update | |
git config --global user.email "[email protected]" #update | |
git remote add upstream https://github.com/european-modelling-hubs/RespiCast-SyndromicIndicators.git | |
git fetch --all | |
git checkout -b pr-new-branch upstream/main | |
env: | |
GITHUB_TOKEN: ${{ secrets.Secret_PUSH_ACCESS_RespiCast }} #same as for step3 | |
# Step 5: Calculate Wednesday's date of the current week | |
- name: Calculate Wednesday's date | |
id: calculate_wednesday | |
run: | | |
# Get the current day of the week (1=Monday, ..., 7=Sunday) | |
weekday=$(date +%u) | |
# Calculate how many days to add or subtract to get to Wednesday (3) | |
offset=$((3 - weekday)) | |
# Calculate the date of the Wednesday (if offset is negative, subtract days) | |
wednesday_date=$(date -d "$offset days" +%Y-%m-%d) | |
echo "Wednesday's date is $wednesday_date" | |
# Set the output | |
echo "::set-output name=wednesday_date::$wednesday_date" | |
# Step 6: make a copy of the needed files from data repository | |
- name: Copy model-output file | |
run: | | |
wednesday_date=${{ steps.calculate_wednesday.outputs.wednesday_date }} | |
cp ./source-repo/Forecasting-hubs_models/model_output/Syndromic_indicators/${wednesday_date}-ECDC-soca_simplex.csv \ | |
./destination-repo/model-output/ECDC-soca_simplex/ | |
cp ./source-repo/Forecasting-hubs_models/model_output/Syndromic_indicators/${wednesday_date}-ECDC-SARIMA.csv \ | |
./destination-repo/model-output/ECDC-SARIMA/ | |
#cp ./data-repo/archive/yyyy-mm-dd-TeamName-ModelName.csv ./model-output/ECDC | |
# Step 7?: commit changes to the new brach! This step is needed in order | |
# to succesfully open the subsequent pull request | |
- run: | | |
cd ./destination-repo/ | |
wednesday_date=${{ steps.calculate_wednesday.outputs.wednesday_date }} | |
git add ./model-output/ECDC-soca_simplex/${wednesday_date}-ECDC-soca_simplex.csv | |
git add ./model-output/ECDC-SARIMA/${wednesday_date}-ECDC-SARIMA.csv | |
git commit -m "AutoSubmitPR" | |
git push -u origin pr-new-branch | |
# Step 8: Finally, open the pull request from local pr-new-branch to the main branch | |
# secrets.MY_PAT_SECRET is a repository secret you have to create in your forked repository | |
# containing a valid PERSONAL ACCESS TOKEN for YourGitHubUserName. | |
# Without this secret the pr create fails with "Resource not accessible by integration" error | |
- name: Open the pull requests | |
run: | | |
cd ./destination-repo/ | |
gh pr create --head ECDC-modelling-team:pr-new-branch --base main --title 'PR Title' --body 'PR Body' | |
env: | |
GH_TOKEN: ${{ secrets.MY_PAT_SECRET }} #Probably largely the same token (?) - one for respicast, one for modelling repo. |