Skip to content

Commit

Permalink
copy files from zephyr-request
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasjucker committed Nov 11, 2024
1 parent f08d04e commit 2d57fe0
Show file tree
Hide file tree
Showing 16 changed files with 640 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/data-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Data Request
about: Use this template to submit a request for data processing
labels: data request

---

# Zephyr Data Request

## Instructions

1. Give this issue a meaningful title.
2. Replace `PASTE_YOUR_REQUEST_HERE` with your request that you copied to clipboard:
```json
PASTE_YOUR_REQUEST_HERE
```
3. Click on "Preview" to verify that the JSON format of your request is correctly formatted and displayed within a code block.
4. Click on "Submit new issue".

Zephyr Data Request will now process your data based on the request you provided here. Once the processing is successful, it will post a link in this issue.
The processed data will be available under that link for up to **7 days**.

If you encounter any problems, please open a discussion in the [C2SM forum](https://github.com/C2SM/Tasks-Support/discussions).

## Status Labels

Labels reflect the current state of your request:

![Static Badge](https://img.shields.io/badge/submitted-yellow) - Your request is currently under processing. Please wait for further updates.

![Static Badge](https://img.shields.io/badge/completed-green) - Your request has been successfully processed. You can download your data using the provided link.

![Static Badge](https://img.shields.io/badge/failed-red) - Unfortunately, your request could not be processed. Please refer to the log files in the zip file at the download link for more details.

![Static Badge](https://img.shields.io/badge/aborted-lightgray) - Your request was aborted. This might be due to a timeout. Please try again or contact support if the problem persists.
54 changes: 54 additions & 0 deletions .github/workflows/close_PR_and_delete_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Close PR and delete branch
on:
issue_comment:
types: [created]

jobs:
CloseFinishedPR:
if: github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'auto-generated')
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get install jq
- name: Checkout repository
uses: actions/checkout@v2
- name: Set env variables
run: |
echo "PR_DELETE=$(jq -r '.PR_DELETE' keywords.json)" >> $GITHUB_ENV
- name: Close PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prComment = context.payload.comment.body;
if (!prComment.includes(process.env.PR_DELETE)) {
console.log(`The PR comment does not contain the string "${process.env.PR_DELETE}".`);
return;
}
await github.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
state: 'closed'
});
- name: Delete branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prComment = context.payload.comment.body;
if (!prComment.includes(process.env.PR_DELETE)) {
console.log(`The PR comment does not contain the string "${process.env.PR_DELETE}".`);
return;
}
const pr = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const branchName = pr.data.head.ref;
await github.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/' + branchName
});
36 changes: 36 additions & 0 deletions .github/workflows/close_old_data_request_issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Close old data request issues
on:
schedule:
- cron: '0 0 * * *' # Run this workflow every day at midnight
workflow_dispatch:

env:
DAYS: 7
jobs:
closeOldIssues:
runs-on: ubuntu-latest
steps:
- name: Close old data request issues
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const max_age = process.env.DAYS * 24 * 60 * 60 * 1000;
const now = new Date();
const issues = await github.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'data request',
state: 'open'
});
for (const issue of issues.data) {
const createdAt = new Date(issue.created_at);
if (now - createdAt > max_age) {
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
}
}
82 changes: 82 additions & 0 deletions .github/workflows/convert_issue_to_PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Forward request to PR
on:
issues:
types: [labeled]

jobs:
createPullRequest:
if: github.event.label.name == 'data request'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Create new branch and commit
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
git checkout -b issue-${{ github.event.issue.number }}/request
echo "This is a new file" > newfile.txt
git add newfile.txt
git commit -m "Add new file for issue #${{ github.event.issue.number }}"
git push origin issue-${{ github.event.issue.number }}/request
- name: Create Pull Request
id: create_pr
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = await github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Request #${context.issue.number}`,
head: `issue-${context.issue.number}/request`,
base: 'main',
body: `Request triggered by #${context.issue.number}`
});
return pr.data.number;
- name: Extract JSON
id: extract
run: |
BODY='${{ github.event.issue.body }}'
JSON=$(echo "$BODY" | sed -n '/```json/,/```/p' | sed '/```json/d' | sed '/```/d')
echo "$JSON" > json.txt
- name: Add issue comment to PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const issueComment = context.payload.issue.body;
const prNumber = ${{ steps.create_pr.outputs.result }};
const JSON = fs.readFileSync('json.txt', 'utf8');
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `submit request ${JSON}`
});
- name: Add label to issue
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['submitted']
});
- name: Add label to PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prNumber = ${{ steps.create_pr.outputs.result }};
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['auto-generated']
});
40 changes: 40 additions & 0 deletions .github/workflows/forward_PR_comment_to_issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Forward Download Link to Issue
on:
issue_comment:
types: [created]

jobs:
forwardDownloadLinkToIssue:
if: github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'auto-generated')
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get install jq
- name: Checkout repository
uses: actions/checkout@v2
- name: Set env variables
run: |
echo "DOWNLOAD_LINK=$(jq -r '.DOWNLOAD_LINK' keywords.json)" >> $GITHUB_ENV
- name: Forward comment to issue
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prComment = context.payload.comment.body;
if (!prComment.includes(process.env.DOWNLOAD_LINK)) {
console.log(`The PR comment does not contain the string "${process.env.DOWNLOAD_LINK}".`);
return;
}
const pr = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const branchName = pr.data.head.ref;
const issueNumber = branchName.split('-')[1].split('/')[0];
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `Your data is ready for up to 7 days: ${prComment}`
});
62 changes: 62 additions & 0 deletions .github/workflows/report_PR_status_as_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Report PR status as label
on:
issue_comment:
types: [created]

jobs:
reportPRStatusAsLabel:
if: github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'auto-generated')
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get install jq
- name: Checkout repository
uses: actions/checkout@v2
- name: Set env variables
run: |
echo "PR_FAIL=$(jq -r '.PR_FAIL' keywords.json)" >> $GITHUB_ENV
echo "PR_SUCCESS=$(jq -r '.PR_SUCCESS' keywords.json)" >> $GITHUB_ENV
echo "PR_ABORT=$(jq -r '.PR_ABORT' keywords.json)" >> $GITHUB_ENV
- name: Update label
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const branchName = pr.data.head.ref;
const issueNumber = branchName.split('-')[1].split('/')[0];
if (context.payload.comment.body.includes(process.env.PR_FAIL) ||
context.payload.comment.body.includes(process.env.PR_SUCCESS) ||
context.payload.comment.body.includes(process.env.PR_ABORT)) {
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'submitted'
});
} if (context.payload.comment.body.includes(process.env.PR_FAIL)) {
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['failed']
});
} if (context.payload.comment.body.includes(process.env.PR_SUCCESS)){
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['completed']
});
} if (context.payload.comment.body.includes(process.env.PR_ABORT)){
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['aborted']
});
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Center for Climate Systems Modeling

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.0
23 changes: 23 additions & 0 deletions jenkins/Cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def https_public_root = '/net/co2/c2sm-data/jenkins/extpar-request'

pipeline {
agent {
node {
label 'atmos'
}
}
stages {
stage('Cleanup HTTPS-server') {
steps {
sh """
python3 src/cleanup.py --path ${https_public_root} --threshold 7 --exclude ${https_public_root}/file_index
"""
}
}
}
post {
always {
deleteDir()
}
}
}
Loading

0 comments on commit 2d57fe0

Please sign in to comment.