name: Setup directories etc. description: >- Set up the source code and build directories (plus some environmental tweaks) inputs: srcdir: required: false default: ${{ github.workspace }} description: >- Directory to (re-)checkout source codes. This will be created if absent. If there is no `configure` file that is also generated inside. builddir: required: false default: ${{ github.workspace }} description: >- Where binaries and other generated contents go. This will be created if absent. make-command: required: false type: string default: 'make' description: >- The command of `make`. makeup: required: false type: boolean # Note that `default: false` evaluates to a string constant # `'false'`, which is a truthy value :sigh: # https://github.com/actions/runner/issues/2238 default: '' description: >- If set to true, additionally runs `make up`. checkout: required: false type: boolean default: true description: >- If set to '' (false), skip running actions/checkout. This is useful when you don't want to overwrite a GitHub token that is already set up. dummy-files: required: false type: boolean default: '' description: >- If set to true, creates dummy files in build dir. fetch-depth: required: false default: '1' description: The depth of commit history fetched from the remote repository clean: required: false type: boolean default: '' description: >- If set to true, clean build directory. outputs: {} # nothing? runs: using: composite steps: # Note that `shell: bash` works on both Windows and Linux, but not # `shell: sh`. This is because GitHub hosted Windows runners have # their bash manually installed. - shell: bash run: | mkdir -p ${{ inputs.srcdir }} mkdir -p ${{ inputs.builddir }} # Did you know that actions/checkout works without git(1)? We are # checking that here. - id: which shell: bash run: | echo "git=`command -v git`" >> "$GITHUB_OUTPUT" echo "sudo=`sudo true && command -v sudo`" >> "$GITHUB_OUTPUT" echo "autoreconf=`command -v autoreconf`" >> "$GITHUB_OUTPUT" - if: steps.which.outputs.git shell: bash run: | git config --global core.autocrlf false git config --global core.eol lf git config --global advice.detachedHead 0 git config --global init.defaultBranch garbage - if: inputs.checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 with: path: ${{ inputs.srcdir }} fetch-depth: ${{ inputs.fetch-depth }} - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 with: path: ${{ inputs.srcdir }}/.downloaded-cache key: ${{ runner.os }}-${{ runner.arch }}-downloaded-cache - if: steps.which.outputs.autoreconf shell: bash working-directory: ${{ inputs.srcdir }} run: ./autogen.sh --install # This is for MinGW. - if: runner.os == 'Windows' shell: bash run: echo "GNUMAKEFLAGS=-j$((2 * NUMBER_OF_PROCESSORS))" >> $GITHUB_ENV - if: runner.os == 'Linux' shell: bash run: echo "GNUMAKEFLAGS=-sj$((1 + $(nproc)))" >> "$GITHUB_ENV" # macOS' GNU make is so old that they doesn't understand `GNUMAKEFLAGS`. - if: runner.os == 'macOS' shell: bash run: echo "MAKEFLAGS=-j$((1 + $(sysctl -n hw.activecpu)))" >> "$GITHUB_ENV" - if: inputs.makeup shell: bash working-directory: ${{ inputs.srcdir }} run: | touch config.status .rbconfig.time for mk in Makefile GNUmakefile; do sed -f tool/prereq.status template/$mk.in > $mk done make up # Cleanup, runs even on failure - if: always() && inputs.makeup shell: bash working-directory: ${{ inputs.srcdir }} run: | rm -f config.status .rbconfig.time \ Makefile GNUmakefile uncommon.mk enc.mk noarch-fake.rb - if: steps.which.outputs.sudo shell: bash run: | sudo chmod -R go-w /usr/share chmod -v go-w $HOME $HOME/.config || : declare -a dirs # -A is not supported by old bash, e.g. macos SAVE_IFS="$IFS" IFS=:; set $PATH for d do while [ -d "$d" ]; do case "$IFS${dirs[*]}$IFS" in *"$IFS$d$IFS"*) ;; *) dirs+=("$d");; esac d="${d%/*}" done done IFS="$SAVE_IFS" sudo chmod -v go-w "${dirs[@]}" || : - if: inputs.dummy-files == 'true' shell: bash id: dummy-files working-directory: ${{ inputs.builddir }} run: | : Create dummy files in build dir set {{a..z},{A..Z},{0..9},foo,bar,test,zzz}.rb for file; do \ echo > $file "raise 'do not load $file'"; \ done # drop {a..z}.rb if case-insensitive filesystem grep -F A.rb a.rb > /dev/null && set "${@:27}" echo clean="cd ${{ inputs.builddir }} && rm $*" >> $GITHUB_OUTPUT - if: inputs.clean == 'true' shell: bash id: clean run: | echo distclean='cd ${{ inputs.builddir }} && ${{ inputs.make-command }} distclean' >> $GITHUB_OUTPUT echo remained-files='find ${{ inputs.builddir }} -ls' >> $GITHUB_OUTPUT [ "${{ inputs.builddir }}" = "${{ inputs.srcdir }}" ] || echo final='rmdir ${{ inputs.builddir }}' >> $GITHUB_OUTPUT - name: clean uses: gacts/run-and-post-run@81b6ce503cde93862cec047c54652e45c5dca991 # v1.4.3 with: working-directory: post: | ${{ steps.dummy-files.outputs.clean }} ${{ steps.clean.outputs.distclean }} ${{ steps.clean.outputs.remained-files }} ${{ steps.clean.outputs.final }} # rmdir randomly fails due to launchable files continue-on-error: true