Production Diff Staging #710
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: Production Diff Staging | |
on: | |
push: | |
branches: | |
- patch-open-issue | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
diff: | |
runs-on: ubuntu-20.04 | |
env: | |
AWS_S3_ENDPOINT: ${{ secrets.DO_S3_ENDPOINT }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.DO_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.DO_SECRET_ACCESS_KEY }} | |
AWS_S3_BUCKET: edm-publishing | |
outputs: | |
matrix: ${{ steps.diff.outputs.matrix }} | |
notify: ${{ steps.diff.outputs.notify }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install Dependencies | |
run: ./run.sh install | |
- name: Compute diff matrix | |
id: diff | |
shell: python | |
run: | | |
import json | |
import os | |
import os | |
diff=os.popen('./run.sh diff_list').readlines() | |
diff=[d.replace('\n', '') for d in diff] | |
diff_json=json.dumps(json.dumps(diff)) | |
print(len(diff)) | |
print(str(len(diff))) | |
os.system('''echo "::set-output name=notify::{}"'''.format(str(len(diff)))) | |
os.system('''echo "::set-output name=matrix::{}"'''.format(diff_json)) | |
- name: notify? | |
run: | | |
echo ${{ steps.diff.outputs.notify }} | |
- name: Print Matrix | |
run: | | |
echo ${{ steps.diff.outputs.matrix }} | |
- name: test notify | |
run: echo ${{ steps.diff.outputs.notify }} | |
- name: test notify | |
if: steps.diff.outputs.notify != '0' | |
run: echo ${{ steps.diff.outputs.notify }} | |
- name: test notify | |
if: steps.diff.outputs.notify != 0 | |
run: echo ${{ steps.diff.outputs.notify }} | |
notify: | |
runs-on: ubuntu-20.04 | |
if: needs.diff.outputs.notify != '0' | |
needs: [diff] | |
env: | |
AWS_S3_ENDPOINT: ${{ secrets.DO_S3_ENDPOINT }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.DO_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.DO_SECRET_ACCESS_KEY }} | |
AWS_S3_BUCKET: edm-publishing | |
strategy: | |
matrix: | |
dataset: ${{ fromJSON(needs.diff.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install Dependencies | |
run: ./run.sh install | |
- name: Random Sleep | |
run: sleep $[ ( $RANDOM % 10 ) + 1 ]s | |
- name: Get Category | |
id: category | |
run: | | |
category=$(cat metadata.json | jq -r '.[] | select( .name | contains("${{ matrix.dataset }}"))' | jq -r '.category') | |
echo "::set-output name=category::$category" | |
- uses: actions/github-script@v3 | |
name: Create Issue to Publish (if it doesn't exist) | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
let category; | |
if ('${{ steps.category.outputs.category }}' === '') { | |
category = '🚕 Other' | |
} else { | |
category = '${{ steps.category.outputs.category }}' | |
} | |
const title = `[publish] ${{ matrix.dataset }}`; | |
const body = ` | |
## Difference Detected Between \`Production\` and \`Staging\` in the following dataset(s) | |
## Dataset(s) | |
\`\`\`yml | |
- ${{ matrix.dataset }} | |
\`\`\` | |
## Next Steps: | |
If you have manually checked above files and they seem to be ok, comment \`[publish]\` under this issue. | |
This would allow github actions to move staging files to production. | |
Feel free to close this issue once it's all complete. Thanks! | |
`; | |
const issues = await github.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open' | |
}); | |
const filtered = issues.data.filter(issue => issue.title === title) | |
if (filtered.length > 0) { | |
console.log('Issue Already Exists') | |
} else { | |
github.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: title, | |
body: body, | |
assignees: ["rtblair", "jpiacentinidcp", "ileoyu", "OmarOrtiz1"], | |
labels: ['staging', category] | |
}); | |
} |