Skip to content

Commit

Permalink
🐛 (svg-tester) commit svg diffs to different branches
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Feb 23, 2024
1 parent 28bf7cf commit b545bec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/svg-compare-all-views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
if: ${{ github.repository_owner == 'owid' }}
shell: bash
run: |
echo "PUSH_BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
echo "PUSH_BRANCH_NAME=${{ github.ref_name }}__all-views" >> $GITHUB_ENV
echo "TOKEN=${{ secrets.GITHUBPAT }}" >> $GITHUB_ENV
- name: Set branch name and token for runs from a fork
if: ${{ github.repository_owner != 'owid' }}
shell: bash
run: |
echo "PUSH_BRANCH_NAME=${{ github.repository_owner }}/${{ github.ref_name }}" >> $GITHUB_ENV
echo "PUSH_BRANCH_NAME=${{ github.repository_owner }}/${{ github.ref_name }}__all-views" >> $GITHUB_ENV
echo "TOKEN=${{ github.token }}" >> $GITHUB_ENV
# Checkout the owid-grapher-svgs repo into a subfolder. Use a Personal Access Token for checkout so the
Expand All @@ -35,20 +35,13 @@ jobs:
path: owid-grapher-svgs
token: ${{ env.TOKEN }}

# Create a branch on that repo that matches the branch name we are on in the owid-grapher repo
# Switch to or create a branch on that repo that matches the branch name we are on in the owid-grapher repo
# but only do this if we are not on master in owid-graphers (in this case we want to commit and push on master
# in owid-grapher-svgs as well)
- name: create owid-grapher-svgs local branch
if: ${{ env.PUSH_BRANCH_NAME != 'master'}}
working-directory: owid-grapher-svgs
continue-on-error: true
run: git branch ${{ env.PUSH_BRANCH_NAME }} || echo "Branch ${{ env.PUSH_BRANCH_NAME }} already exists"

# Checkout the branch we just created (but not if we are on master in owid-grapher)
- name: checkout owid-grapher-svgs local branch
if: ${{ env.PUSH_BRANCH_NAME != 'master'}}
working-directory: owid-grapher-svgs
run: git checkout ${{ env.PUSH_BRANCH_NAME }}
run: git branch ${{ env.PUSH_BRANCH_NAME }} && git checkout ${{ env.PUSH_BRANCH_NAME }}

# Run the verify tool overwriting any svgs. Stdout is piped to compare-result which will be a 0 byte file if everything works or contain failed grapher ids otherwise
- name: Generate SVGs and compare to reference
Expand All @@ -57,7 +50,7 @@ jobs:
env:
# using "ternary operator" from https://github.com/actions/runner/issues/409#issuecomment-752775072
RM_ON_ERROR: ${{ env.PUSH_BRANCH_NAME == 'master' && '' || '--rm-on-error' }}
run: node --enable-source-maps itsJustJavascript/devTools/svgTester/verify-graphs.js -i owid-grapher-svgs/configs -o owid-grapher-svgs/all-views/svg -r owid-grapher-svgs/all-views/svg --ids-from-file owid-grapher-svgs/most-viewed-charts.txt --all-views $RM_ON_ERROR > compare-result
run: node --enable-source-maps itsJustJavascript/devTools/svgTester/verify-graphs.js -i owid-grapher-svgs/configs -o owid-grapher-svgs__all-views/svg -r owid-grapher-svgs__all-views/svg --ids-from-file owid-grapher-svgs/most-viewed-charts.txt --all-views $RM_ON_ERROR > compare-result

# If the last step failed we want to commit all changed svgs and push them to the new branch on the owid-grapher-svgs repo
- uses: stefanzweifel/git-auto-commit-action@v4
Expand All @@ -66,7 +59,7 @@ jobs:
repository: ./owid-grapher-svgs/
branch: ${{ env.PUSH_BRANCH_NAME }}
push_options: "--force"
commit_message: Automated commit with svg differences of all views triggered by commit https://github.com/owid/owid-grapher/commit/${{github.sha}}
commit_message: Automated commit with svg differences (all views) triggered by commit https://github.com/owid/owid-grapher/commit/${{github.sha}}

# The action fails if there were any errors.
- name: Fail with error message if we had errors
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/svg-compare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,13 @@ jobs:
path: owid-grapher-svgs
token: ${{ env.TOKEN }}

# Create a branch on that repo that matches the branch name we are on in the owid-grapher repo
# Switch to or create a branch on that repo that matches the branch name we are on in the owid-grapher repo
# but only do this if we are not on master in owid-graphers (in this case we want to commit and push on master
# in owid-grapher-svgs as well)
- name: create owid-grapher-svgs local branch
if: ${{ env.PUSH_BRANCH_NAME != 'master'}}
working-directory: owid-grapher-svgs
continue-on-error: true
run: git branch ${{ env.PUSH_BRANCH_NAME }} || echo "Branch ${{ env.PUSH_BRANCH_NAME }} already exists"

# Checkout the branch we just created (but not if we are on master in owid-grapher)
- name: checkout owid-grapher-svgs local branch
if: ${{ env.PUSH_BRANCH_NAME != 'master'}}
working-directory: owid-grapher-svgs
run: git checkout ${{ env.PUSH_BRANCH_NAME }}
run: git branch ${{ env.PUSH_BRANCH_NAME }} && git checkout ${{ env.PUSH_BRANCH_NAME }}

# Run the verify tool overwriting any svgs. Stdout is piped to compare-result which will be a 0 byte file if everything works or contain failed grapher ids otherwise
- name: Generate SVGs and compare to reference
Expand Down

0 comments on commit b545bec

Please sign in to comment.