Skip to content

Refactor import and auto-commit Base images #19

@josecelano

Description

@josecelano

The workflow import-base-images.yml allows us to import new images from the library into this repo.

We have to change the workflow to start using the Librarian.

There are two big questions:

  1. What should be moved to the Librarian and what should be part only of this website repo.
  2. We detected some problems with the current solution. Upgrading the library (submodule) could imply more than one secondary task. Right now we are only processing changes related to Base images, but the library update could imply other changes in the site that might require new workflows. Besides, working directly with the main branch leads to inconsistencies.

And some known problems:

There was also at least one accepted refactor. We have to use a PR instead of pushing directly to the main branch after every auto-commit. For example, if we create a commit adding a base image and we run again the workflow the commit is going to be created again because the library has not been updated yet in the main branch. In order to do that we have to split the workflow in two: one workflow is going to receive the event (the library has been updated) and it will create the new PR (I'm not sure if a PR created by the GitHub API triggers the workflows). The entry workflow would be called something like create-pr-for-library-update.yml. That workflow is going to create the new PR that will trigger the update-library.yml workflow.

Proposal 1: nested pull requests

On solution we proposed was:

We create a new workflow called: update-library.yml. This workflow will update the library submodule and will trigger a new workflow (import-base-images.yml) in a nested branch. That nested PR will import the Base image into this repo. The nested PR have to be merged manually into the parent PR.

Pros:

  • We can easily add new tasks that we want to trigger when the library is updated.

Cons:

  • We have to merge two PRs manually. Merge them automatically will require some kind of notification to the parent workflow.
  • We have to implement a step to automatically generate the child PR from the parent one. That is going to couple us more to GitHub.

Proposal 2: keep only one workflow for main and secondary tasks

We can try to keep it simple only with one workflow: update-library.yml. Secondary tasks could be steps in this workflow. For example, we can have a step to import the Base images. If we need to add more action we can add more steps.

name: Import Base images from remote media library

on:
  push:
    branches: [ issue-library-update* ]

jobs:
  import-base-images:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:  
          submodules: 'true'

      - name: Setup DVC
        uses: iterative/setup-dvc@v1

      - name: Update library submodule and auto-commit library update
        id: update-library

        # In the future we can add a filter to pull only Base images
        # This action could return a json list of imported images
      - name: Import changed dvc files
        run: nautilus-librarian dvc pull --from-diff
        env:
          nl_dvc_diff: ${{ steps.update-library.outputs.dvc_diff }}
          AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
          AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }}

        # This action is a specific action only used in this repo.
        # Filter Base images from previous output.
      - name: Resize Base images into a different tmp dir
        id: resize-image
        uses: ./.github/actions/resize-image
        with:
          dvc_diff: ${{ steps.update-library.outputs.dvc_diff }}
          dest_dir: /tmp/whatever/resized
          width: 512
          height: 512

      - name: Change file format of synched images (and copy to final dir)
        id: change-image-file-format
        uses: ./.github/actions/change-image-file-format
        with:
          dest_dir: public/images
          format: jpg

      - name: Auto-commit files
        id: auto-commit
        run: nautilus-librarian git auto-commit --file-list {...} --message"new large drawing {filename}"

      - name: Build website if Base images have been added
        if: ${{ steps.auto-commit.outputs.changes_detected == 'true' }}
        run: |
          npm install
          npm run build

      - name: Deploy website if Base images have been added
        if: ${{ steps.auto-commit.outputs.changes_detected == 'true' }}
        uses: JamesIves/[email protected]
        with:
          branch: gh-pages
          folder: public

Specific actions for this repo (resize-image and change-image-file-format) could be merged into a single embedded action (process-base-images).

NOTES:

  • Notice that we auto-commit the library update at the beginning. That should not be a problem we use a PR. In the current solution, we are pushing directly to the main branch and that can create inconsistencies.

I would start with proposal 2 and move to proposal 1 if needed.

@da2ce7 @yeraydavidrodriguez could you add your thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions