summaryrefslogtreecommitdiff
path: root/.github/actions/setup/directories/action.yml
blob: 4150288ed770843bdbd5f4883447ec4aa58b15ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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.

  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.

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=`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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      with:
        path: ${{ inputs.srcdir }}

    - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4.2.1
      with:
        path: ${{ inputs.srcdir }}/.downloaded-cache
        key: downloaded-cache

    - if: steps.which.outputs.autoreconf
      shell: bash
      working-directory: ${{ inputs.srcdir }}
      run: ./autogen.sh

    # 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 --all)))" >> "$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
        touch .rbconfig.time
        sed -f tool/prereq.status template/Makefile.in > Makefile
        sed -f tool/prereq.status template/GNUmakefile.in > GNUmakefile
        make up

    # Cleanup, runs even on failure
    - if: always() && inputs.makeup
      shell: bash
      working-directory: ${{ inputs.srcdir }}
      run: rm -f config.status Makefile rbconfig.rb .rbconfig.time

    - if: steps.which.outputs.sudo
      shell: bash
      run: |
        sudo chmod -R go-w /usr/share
        chmod -v go-w $HOME $HOME/.config || :
        sudo bash -c 'IFS=:; for d in '"$PATH"'; do chmod -v go-w $d; done' || :

    - if: inputs.dummy-files == 'true'
      shell: bash
      working-directory: ${{ inputs.builddir }}
      run: |
        : Create dummy files in build dir
        for basename in {a..z} {A..Z} {0..9} foo bar test zzz; do
          echo > ${basename}.rb "raise %(do not load ${basename}.rb)"
        done