Platane / snk

🟩⬜ Generates a snake game from a github user contributions graph and output a screen capture as animated svg or gif
https://platane.github.io/snk
4.22k stars 1.03k forks source link

Able to wipe git history for master/main branch #36

Closed Technetium1 closed 2 years ago

Technetium1 commented 2 years ago

This needs to have a warning. The action should not destroy the commit history. Luckily GitHub support was able to recover my last commit.

Example:

name: Snake

on:
  # run automatically every 6 hours
  schedule:
    - cron: "0 */6 * * *"

# This command allows us to run the Action automatically from the Actions tab.
  workflow_dispatch:

  push:
    branches:
    - master

jobs:
  generate:
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      # generates a snake game from a github user (<github_user_name>) contributions graph, output a svg animation at <svg_out_path>
      - name: generate github-contribution-grid-snake.svg
        uses: Platane/snk/svg-only@v2
        with:
          github_user_name: ${{ github.repository_owner }}
          outputs: |
            snake/github-contribution-grid-snake.svg?color_snake=purple
            snake/github-contribution-grid-snake-dark.svg?palette=github-dark&color_snake=purple
      # push the content of <build_dir> to a branch
      # the content will be available at https://raw.githubusercontent.com/<github_user>/<repository>/<target_branch>/<file> , or as github page
      - name: push github-contribution-grid-snake.svg to the output branch
        uses: crazy-max/ghaction-github-pages@v2.6.0
        with:
          target_branch: master
          build_dir: dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Technetium1 commented 2 years ago

Related https://github.com/Platane/snk/issues/13

Platane commented 2 years ago

How would you want me to address this ?

As you noticed this action ( Platane/snk ) did not manipulate your git repository. The second one ( crazy-max/ghaction-github-pages) did. There are already comments to explain what each action does.

huuquyet commented 4 months ago

I found the way to commit files without overwrite the output branch, just use actions/checkout@v4 instead of crazy-max/ghaction-github-pages:


    steps:
+      # checkout output branch 
+      - name: checkout output branch
+        uses: actions/checkout@v4
+        with:
+          ref: output

      # generates a snake game from a github user (<github_user_name>) contributions graph, output a svg animation at <svg_out_path>
      - name: generate github-contribution-grid-snake.svg
        uses: Platane/snk/svg-only@v3
        with:
          github_user_name: ${{ github.repository_owner }}
          outputs: |
-            dist/github-contribution-grid-snake.svg
-            dist/github-contribution-grid-snake-dark.svg?palette=github-dark
            ./github-contribution-grid-snake.svg
            ./github-contribution-grid-snake-dark.svg?palette=github-dark
      # push the content of <build_dir> to a branch
      # the content will be available at https://raw.githubusercontent.com/<github_user>/<repository>/<target_branch>/<file> , or as github page
      - name: push github-contribution-grid-snake.svg to the output branch
-        uses: crazy-max/ghaction-github-pages@v3.1.0
-        with:
-          target_branch: output
-          build_dir: dist
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          git config user.name "github-actions[bot]"
+          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+          git add .
+          git commit -m "Update github-contribution-grid-snake by [bot]"
+          git push