stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.98k stars 227 forks source link

action not running when using alpine:latest container on job #166

Closed AnthonyPoschen closed 3 years ago

AnthonyPoschen commented 3 years ago

Version of the Action v4

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior: use an alpine base container for the job with this task.

Expected behavior expect the action to run and commit / tag commits.

Screenshots https://github.com/zanven42/workflow-debugger/actions/runs/1019597903

Used Workflow

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    runs-on: ubuntu-latest
    container: alpine:latest
    steps:
      - name: Obtain Latest Git ONLY within container for checkout
        run: apk add git docker --update-cache

      - name: Checkout Repo Action
        uses: actions/checkout@v2
        with:
          fetch-depth: '0'
      - name: Buildx docker image build and push images
        id: build
        run: |
          echo "testing" >> README.md

      - name: commit changes
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "[CICD] commit"

Additional context below is the logs output when starting the action. If it is known what packages are needed for this action a minimal alpine image could be setup for this action to use so that it can run in isolation cleanly and avoid this issue.


Error: spawn bash ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn bash',
  path: 'bash',
  spawnargs: [
    '/__w/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh'
  ]
}
Error: spawn bash ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)```
AnthonyPoschen commented 3 years ago

this issue is resolved locally with apk add bash not sure if more desirable to leave it as a documented requirement or to look at potentially supporting "sh" for things like alpine images that are very minimal, or potentially running the action within its own docker image with minimal requirements met.

stefanzweifel commented 3 years ago

I think this could be solved by simply updating the shebang like below.

-#!/bin/bash
+#!/bin/sh

# Remaining entrypoint.sh code …

entrypoint.sh doesn't use specific bash features and would allow users like you, which use their own container image for jobs to use the Action without installing additional software. Would you agree @zanven42?

The Action used Docker before v4. (We've moved to a simple node environment to allow users to use pre-commit tools like husky.) Switching back to Docker is currently not on my radar. Not a big fan of downloading docker images/containers "just" to run a shell-script to execute a couple of git-commands. :)

AnthonyPoschen commented 3 years ago

@stefanzweifel yeah that would resolve the issue perfectly fine and minimally. Still trying to find time to write my first action, since i don't get how a "simple node environment" is simpler than a tiny docker image for a run environment in the github actions world yet. If it requires less downloaded MB's then its more optimal :).

stefanzweifel commented 3 years ago

@zanven42 I've created a pull request (#167) where the Action now uses /bin/sh instead of /bin/bash. If you want you can test this new Action by updating your workflow like below:

-- uses: stefanzweifel/git-auto-commit-action@v4
+- uses: stefanzweifel/git-auto-commit-action@issue-166

Once the PR is merged and a new version is released, you can revert back to v4. I will test the changes over the next couple of days in my own projects and release a new version in the middle of the coming week.


Still trying to find time to write my first action, since i don't get how a "simple node environment" is simpler than a tiny docker image for a run environment in the github actions world yet.

As always in software development: it depends. :) If the Action you want to write is very specific and not a "general" utitliy – like git-auto-commit – I would definitely go down the Docker route. There you have full control over the environment.

As mentioned, in v1 to v3 this Action was using this Dockerfile. This blocked users from using the Action which were using pre-commit hooks provided by husky. As husky is such a widely used tool, I've switched the runtime from Docker to node. If I remember correctly, in v1-v3 it also took a couple of seconds to download the Docker images. It wasn't too bad. However I felt it was a unnecessary as the Action just runs some git-commands.

stefanzweifel commented 3 years ago

Hey again.

I've commented in the PR already (https://github.com/stefanzweifel/git-auto-commit-action/pull/167#issuecomment-878517524), but wanted to update this issue too. The problem is that git-auto-commit actually uses bash-features and is currently not compatible with sh alone. (Was new to me too)

I think the easiest way to resolve this problem, is to update the README/documentation and – as you suggested in the beginning – to add a line that says that the script requires bash. If someone uses a Docker Image like alpine, they would have to install bash to use git-auto-commit.

stefanzweifel commented 3 years ago

I've added a note about the dependency to bash in the README in https://github.com/stefanzweifel/git-auto-commit-action/commit/3568db7bbcf2f869cbd3409043c0768bc912a341.

I'm closing this issue now. Thanks for reporting!