mirror of
				https://github.com/ludeeus/action-shellcheck.git
				synced 2025-10-30 17:38:35 +01:00 
			
		
		
		
	Pass inputs to env before reading (#66)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
		
							
								
								
									
										83
									
								
								action.yaml
									
									
									
									
									
								
							
							
						
						
									
										83
									
								
								action.yaml
									
									
									
									
									
								
							| @@ -58,14 +58,19 @@ runs: | |||||||
|   steps: |   steps: | ||||||
|     - name: Enable problem-matcher |     - name: Enable problem-matcher | ||||||
|       shell: bash |       shell: bash | ||||||
|  |       env: | ||||||
|  |         format: ${{ inputs.format }} | ||||||
|  |         disable_matcher: ${{ inputs.disable_matcher }} | ||||||
|       run: | |       run: | | ||||||
|         problem_matcher_file="${{ github.action_path }}/.github/problem-matcher-${{ inputs.format }}.json" |         problem_matcher_file="${{ github.action_path }}/.github/problem-matcher-${format}.json" | ||||||
|         if [[ ${{ inputs.disable_matcher }} != "true" && -f "$problem_matcher_file"  ]]; then |         if [[ "${disable_matcher}" != "true" && -f "$problem_matcher_file"  ]]; then | ||||||
|           echo "::add-matcher::$problem_matcher_file" |           echo "::add-matcher::$problem_matcher_file" | ||||||
|         fi |         fi | ||||||
|  |  | ||||||
|     - name: Download shellcheck |     - name: Download shellcheck | ||||||
|       shell: bash |       shell: bash | ||||||
|  |       env: | ||||||
|  |         scversion: ${{ inputs.version }} | ||||||
|       run: | |       run: | | ||||||
|         if [[ "${{ runner.os }}" == "macOS" ]]; then |         if [[ "${{ runner.os }}" == "macOS" ]]; then | ||||||
|           osvariant="darwin" |           osvariant="darwin" | ||||||
| @@ -73,7 +78,6 @@ runs: | |||||||
|           osvariant="linux" |           osvariant="linux" | ||||||
|         fi |         fi | ||||||
|  |  | ||||||
|         scversion="${{ inputs.version }}" |  | ||||||
|         baseurl="https://github.com/koalaman/shellcheck/releases/download" |         baseurl="https://github.com/koalaman/shellcheck/releases/download" | ||||||
|  |  | ||||||
|         curl -Lso "${{ github.action_path }}/sc.tar.xz" \ |         curl -Lso "${{ github.action_path }}/sc.tar.xz" \ | ||||||
| @@ -91,42 +95,49 @@ runs: | |||||||
|     - name: Set options |     - name: Set options | ||||||
|       shell: bash |       shell: bash | ||||||
|       id: options |       id: options | ||||||
|  |       env: | ||||||
|  |         severity: ${{ inputs.severity }} | ||||||
|  |         format: ${{ inputs.format }} | ||||||
|       run: | |       run: | | ||||||
|         declare -a options |         declare -a options | ||||||
|         if [[ -n "${{ inputs.severity }}" ]]; then |         if [[ -n "${severity}" ]]; then | ||||||
|           options+=("-S ${{ inputs.severity }}") |           options+=("-S ${severity}") | ||||||
|         fi |         fi | ||||||
|         options+=("--format=${{ inputs.format }}") |         options+=("--format=${format}") | ||||||
|         echo "options=${options[@]}" >> $GITHUB_OUTPUT |         echo "options=${options[@]}" >> $GITHUB_OUTPUT | ||||||
|  |  | ||||||
|     - name: Gather excluded paths |     - name: Gather excluded paths | ||||||
|       shell: bash |       shell: bash | ||||||
|       id: exclude |       id: exclude | ||||||
|  |       env: | ||||||
|  |         ignore: ${{ inputs.ignore }} | ||||||
|  |         ignore_paths: ${{ inputs.ignore_paths }} | ||||||
|  |         ignore_names: ${{ inputs.ignore_names }} | ||||||
|       run: | |       run: | | ||||||
|         declare -a excludes |         declare -a excludes | ||||||
|         set -f # temporarily disable globbing so that globs in input aren't expanded |         set -f # temporarily disable globbing so that globs in input aren't expanded | ||||||
|  |  | ||||||
|         excludes+=("! -path \"*./.git/*\"") |         excludes+=("! -path *./.git/*") | ||||||
|         excludes+=("! -path \"*.go\"") |         excludes+=("! -path *.go") | ||||||
|         excludes+=("! -path \"*/mvnw\"") |         excludes+=("! -path */mvnw") | ||||||
|         if [[ -n "${{ inputs.ignore }}" ]]; then |         if [[ -n "${ignore}" ]]; then | ||||||
|           echo "::warning::ignore is deprecated. Please use ignore_paths instead" |           echo "::warning::ignore is deprecated. Please use ignore_paths instead" | ||||||
|           for path in ${{ inputs.ignore }}; do |           for path in ${ignore}; do | ||||||
|             echo "::debug:: Adding '$path' to excludes" |             echo "::debug:: Adding '$path' to excludes" | ||||||
|             excludes+=("! -path \"*./$path/*\"") |             excludes+=("! -path *./$path/*") | ||||||
|             excludes+=("! -path \"*/$path/*\"") |             excludes+=("! -path */$path/*") | ||||||
|             excludes+=("! -path \"$path\"") |             excludes+=("! -path $path") | ||||||
|           done |           done | ||||||
|         else |         else | ||||||
|           for path in ${{ inputs.ignore_paths }}; do |           for path in ${ignore_paths}; do | ||||||
|             echo "::debug:: Adding '$path' to excludes" |             echo "::debug:: Adding '$path' to excludes" | ||||||
|             excludes+=("! -path \"*./$path/*\"") |             excludes+=("! -path *./$path/*") | ||||||
|             excludes+=("! -path \"*/$path/*\"") |             excludes+=("! -path */$path/*") | ||||||
|             excludes+=("! -path \"$path\"") |             excludes+=("! -path $path") | ||||||
|           done |           done | ||||||
|         fi |         fi | ||||||
|  |  | ||||||
|         for name in ${{ inputs.ignore_names }}; do |         for name in ${ignore_names}; do | ||||||
|           echo "::debug:: Adding '$name' to excludes" |           echo "::debug:: Adding '$name' to excludes" | ||||||
|           excludes+=("! -name $name") |           excludes+=("! -name $name") | ||||||
|         done |         done | ||||||
| @@ -137,26 +148,36 @@ runs: | |||||||
|     - name: Gather additional files |     - name: Gather additional files | ||||||
|       shell: bash |       shell: bash | ||||||
|       id: additional |       id: additional | ||||||
|  |       env: | ||||||
|  |         additional_files: ${{ inputs.additional_files }} | ||||||
|       run: | |       run: | | ||||||
|         declare -a files |         declare -a files | ||||||
|         for file in ${{ inputs.additional_files }}; do |         for file in ${additional_files}; do | ||||||
|           echo "::debug:: Adding '$file' to excludes" |           echo "::debug:: Adding '$file' to additional files" | ||||||
|           files+=("-o -name \"*$file\"") |           files+=("-o -name *$file") | ||||||
|         done |         done | ||||||
|         echo "files=${files[@]}" >> $GITHUB_OUTPUT |         echo "files=${files[@]}" >> $GITHUB_OUTPUT | ||||||
|  |  | ||||||
|     - name: Run the check |     - name: Run the check | ||||||
|       shell: bash |       shell: bash | ||||||
|       id: check |       id: check | ||||||
|  |       env: | ||||||
|  |         scandir: ${{ inputs.scandir }} | ||||||
|  |         check_together: ${{ inputs.check_together }} | ||||||
|  |         exclude_args: ${{ steps.exclude.outputs.excludes }} | ||||||
|  |         additional_file_args: ${{ steps.additional.outputs.files }} | ||||||
|  |         shellcheck_options: ${{ steps.options.outputs.options }} | ||||||
|       run: | |       run: | | ||||||
|         statuscode=0 |         statuscode=0 | ||||||
|         declare -a filepaths |         declare -a filepaths | ||||||
|         shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" |         shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" | ||||||
|  |  | ||||||
|  |         set -f # temporarily disable globbing so that globs in inputs aren't expanded | ||||||
|  |  | ||||||
|         while IFS= read -r -d '' file; do |         while IFS= read -r -d '' file; do | ||||||
|           filepaths+=("$file") |           filepaths+=("$file") | ||||||
|         done < <(find "${{ inputs.scandir }}" \ |         done < <(find "${scandir}" \ | ||||||
|             ${{ steps.exclude.outputs.excludes }} \ |             ${exclude_args} \ | ||||||
|             -type f \ |             -type f \ | ||||||
|             '(' \ |             '(' \ | ||||||
|             -name '*.bash' \ |             -name '*.bash' \ | ||||||
| @@ -185,27 +206,27 @@ runs: | |||||||
|             -o -path '*/.profile' \ |             -o -path '*/.profile' \ | ||||||
|             -o -path '*/profile' \ |             -o -path '*/profile' \ | ||||||
|             -o -name '*.shlib' \ |             -o -name '*.shlib' \ | ||||||
|             ${{ steps.additional.outputs.files }} \ |             ${additional_file_args} \ | ||||||
|             ')' \ |             ')' \ | ||||||
|             -print0) |             -print0) | ||||||
|  |  | ||||||
|         while IFS= read -r -d '' file; do |         while IFS= read -r -d '' file; do | ||||||
|           head -n1 "$file" | grep -Eqs "$shebangregex" || continue |           head -n1 "$file" | grep -Eqs "$shebangregex" || continue | ||||||
|           filepaths+=("$file") |           filepaths+=("$file") | ||||||
|         done < <(find "${{ inputs.scandir }}" \ |         done < <(find "${scandir}" \ | ||||||
|             ${{ steps.exclude.outputs.excludes }} \ |             ${exclude_args} \ | ||||||
|             -type f ! -name '*.*' -perm /111 \ |             -type f ! -name '*.*' -perm /111 \ | ||||||
|             -print0) |             -print0) | ||||||
|  |  | ||||||
|         if [[ -n "${{ inputs.check_together }}" ]]; then |         if [[ -n "${check_together}" ]]; then | ||||||
|           "${{ github.action_path }}/shellcheck" \ |           "${{ github.action_path }}/shellcheck" \ | ||||||
|             ${{ steps.options.outputs.options }} \ |             ${shellcheck_options} \ | ||||||
|             "${filepaths[@]}" || statuscode=$? |             "${filepaths[@]}" || statuscode=$? | ||||||
|         else |         else | ||||||
|           for file in "${filepaths[@]}"; do |           for file in "${filepaths[@]}"; do | ||||||
|             echo "::debug::Checking '$file'" |             echo "::debug::Checking '$file'" | ||||||
|             "${{ github.action_path }}/shellcheck" \ |             "${{ github.action_path }}/shellcheck" \ | ||||||
|               ${{ steps.options.outputs.options }} \ |               ${shellcheck_options} \ | ||||||
|               "$file" || statuscode=$? |               "$file" || statuscode=$? | ||||||
|           done |           done | ||||||
|         fi |         fi | ||||||
| @@ -213,6 +234,8 @@ runs: | |||||||
|         echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT |         echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT | ||||||
|         echo "statuscode=$statuscode" >> $GITHUB_OUTPUT |         echo "statuscode=$statuscode" >> $GITHUB_OUTPUT | ||||||
|  |  | ||||||
|  |         set +f # re-enable globbing | ||||||
|  |  | ||||||
|     - name: Exit action |     - name: Exit action | ||||||
|       shell: bash |       shell: bash | ||||||
|       run: exit ${{steps.check.outputs.statuscode}} |       run: exit ${{steps.check.outputs.statuscode}} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Boris Bera
					Boris Bera