Skip to content

Testing pyrs in the data viewer #156

Testing pyrs in the data viewer

Testing pyrs in the data viewer #156

name: catalog-entry
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # every day at midnight
permissions:
contents: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
validate-and-generate:
timeout-minutes: 10
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- run: |
cat ./feedstock/catalog.yaml
git --no-pager log --oneline -n 4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: validate feedstock entry and generate catalog
uses: leap-stc/data-catalog-actions/leap-catalog@main
with:
generation-single: "./feedstock/catalog.yaml"
output-directory: "./"
- name: Format JSON
run: |
jq -r '.' output/single-feedstock-web-catalog.json | sed '$s/^$//;/^$/d' > formatted.json
mv formatted.json output/single-feedstock-web-catalog.json
cat output/single-feedstock-web-catalog.json | jq
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: single-feedstock-web-catalog.json
path: output/single-feedstock-web-catalog.json
update:
needs: validate-and-generate
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
environment:
name: ${{ github.head_ref }}
url: https://catalog.leap.columbia.edu/?catalog=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.head_ref }}/output/single-feedstock-web-catalog.json
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
token: ${{ steps.app-token.outputs.token }}
- uses: actions/download-artifact@v4
with:
name: single-feedstock-web-catalog.json
path: output
- run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
- name: Commit and Push
run: |
git add output/single-feedstock-web-catalog.json
git commit -m "Auto-update single-feedstock-web-catalog.json" || true # ignore if there is nothing to commit
- name: Push changes
if: github.event_name == 'pull_request'
uses: ad-m/github-push-action@master
with:
github_token: ${{ steps.app-token.outputs.token }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
branch: ${{ github.event.pull_request.head.ref }}
- name: Create Pull Request
id: cpr
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'push'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: "build: update catalog entry"
committer: GitHub <[email protected]>
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
title: Update catalog entry
body: |
- Updates the single-feedstock web catalog for changes on `main`
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-single-feedstock-web-catalog
delete-branch: true
create-or-update-issue:
needs: validate-and-generate
if: failure() && github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Create or Update Issue
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueTitle = 'Validate and Generate Job Failed';
const issueBody = `The validate-and-generate job failed in the scheduled run on ${new Date().toISOString()}.
Please check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for more details.`;
// Search for an existing open issue
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
creator: 'github-actions[bot]',
title: issueTitle
});
if (issues.data.length > 0) {
// Update existing issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues.data[0].number,
body: issueBody
});
console.log(`Updated issue #${issues.data[0].number}`);
} else {
// Create new issue
const newIssue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody
});
console.log(`Created issue #${newIssue.data.number}`);
}