Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Action in this repo that updates simonw/datasette-plugin-template-demo #4

Closed
simonw opened this issue Jun 19, 2020 · 16 comments
Closed
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jun 19, 2020

Would be cool if this repo updated its own demo.

@simonw simonw added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 19, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

This should happen on every push to main.

simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

I have this working now in that it generates the correct set of files here:

Update_push_yml_·_simonw_datasette-plugin_ad04ee6

Next step: push those files to the https://github.com/simonw/datasette-plugin-template-demo repo.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

This is a bit tricky: I want to completely over-write the existing repo contents with the newly generated files, deleting any files that are missing and adding any new ones - all represented by a single commit.

The commit message should link back to the commit in this datasette-plugin repo that caused the changes.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

I think git add -A . will handle the git side of things. So I need to checkout the repo, generate a clean demo with cookiecutter, then replace the checked out content with the files created by cookiecutter and run the commit.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

I think rsync can do this: rsync -av --delete /from-path /to-path

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

Possibly easier: mv ~/old-version/.git ~/new-version - then run the checkin from the new version?

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

And to commit but only if it changed:

timestamp=$(date -u)
git commit -m "Latest data: ${timestamp}" || exit 0

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

I might need to do this to be able to push to the repo:

- name: Checkout private tools
  uses: actions/checkout@v2
  with:
    repository: my-org/my-private-tools
    token: ${{ secrets.GitHub_PAT }} # `GitHub_PAT` is a secret that contains your PAT
    path: my-tools

From https://github.com/actions/checkout#checkout-multiple-repos-private

simonw added a commit that referenced this issue Jun 19, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

git_config_user_name_and_user_email__refs__4_·_simonw_datasette-plugin_20efc27

Need permission to git push to that repo.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

Using a personal access token like this should work:

git remote set-url origin https://simonw:<MYTOKEN>@github.com/simonw/datasette-plugin-template-demo.git

From https://stackoverflow.com/a/18936804

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

I created a token for this: https://github.com/settings/tokens/444691620 - with repo access, called "Push to simonw/datasette-plugin-template-demo"

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

Added that secret to this repo as PERSONAL_ACCESS_TOKEN_FOR_PUSH.

simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

This works now! simonw/datasette-plugin-template-demo@2de806a

It would be cool if it posted a comment on the commit in the datasette-plugin repo linking to the "browse files" for the new demo.

Here's a recipe for posting a commit comment from https://stackoverflow.com/a/58469094:

      - name: Add commit comment
        run: |
          jq -nc '{"body": "test comment"}' | \
          curl -sL  -X POST -d @- \
            -H "Content-Type: application/json" \
            -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
            "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments"

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

echo "Demo: https://github.com/simonw/datasette-plugin-template-demo/tree/$(git rev-parse HEAD)"

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

export FULL_SHA=$(git rev-parse HEAD)
export SHORT_SHA=${FULL_SHA::8}
export NEWLINE=$'\n'
echo '{}' | jq --arg v "Demo: https://github.com/simonw/datasette-plugin-template-demo/tree/$SHORT_SHA" \
          '. + { text: $v }'

simonw added a commit that referenced this issue Jun 19, 2020
simonw added a commit that referenced this issue Jun 19, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

It works, and it adds the comment! acd7aee

@simonw simonw closed this as completed Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant