|
| 1 | +name: "Checkout and install go" |
| 2 | +description: "This action will install go (currently supported version by default). Operator may optionally require the `strategy` input: |
| 3 | + - 'canary', for the latest RC/beta |
| 4 | + - 'latest-stable', for the latest patch release for the currently supported version (this is normally the default, unless nerdctl is lagging) |
| 5 | + - 'old-stable' for the latest patch release of the minimum minor go version nerdctl is supporting" |
| 6 | +inputs: |
| 7 | + cache-dependency-path: |
| 8 | + description: 'Used to specify the path to a dependency file - go.sum' |
| 9 | + strategy: |
| 10 | + default: "" |
| 11 | + description: "You may set this to `canary`, `latest-stable`, or `old-stable`. Otherwise defauls to the explicitly supported version." |
| 12 | + # These below are technically not input variables (that we expect people to specific or change). |
| 13 | + # We are just abusing the system here for convenience, since a composite action does not let you define env. |
| 14 | + # This here is the one, central location where we would update go versions when there is a newly supported go version. |
| 15 | + _current: |
| 16 | + default: "1.23.4" |
| 17 | + description: "What we consider the current blessed go version (typically the latest patch release of the last major.minor version)" |
| 18 | + _stable: |
| 19 | + default: "1.23.x" |
| 20 | + description: "The latest major.minor version we support" |
| 21 | + _old_stable: |
| 22 | + default: "1.22.x" |
| 23 | + description: "The minimum major.minor go version that we still support" |
| 24 | + |
| 25 | +runs: |
| 26 | + using: composite |
| 27 | + steps: |
| 28 | + - name: "Set GO_VERSION environment variable from user strategy" |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + golang::canary(){ |
| 32 | + # Enable extended globbing features to use advanced pattern matching |
| 33 | + shopt -s extglob |
| 34 | + # Get latest golang version and split it in components |
| 35 | + norm=() |
| 36 | + while read -r line; do |
| 37 | + line_trimmed="${line//+([[:space:]])/}" |
| 38 | + norm+=("$line_trimmed") |
| 39 | + done < \ |
| 40 | + <(sed -E 's/^go([0-9]+)[.]([0-9]+)([.]([0-9]+))?(([a-z]+)([0-9]+))?/\1.\2\n\4\n\6\n\7/i' \ |
| 41 | + <(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version) \ |
| 42 | + ) |
| 43 | + # Serialize version, making sure we have a patch version, and separate possible rcX into .rc-X |
| 44 | + [ "${norm[1]}" != "" ] || norm[1]="0" |
| 45 | + norm[1]=".${norm[1]}" |
| 46 | + [ "${norm[2]}" == "" ] || norm[2]="-${norm[2]}" |
| 47 | + [ "${norm[3]}" == "" ] || norm[3]=".${norm[3]}" |
| 48 | + # Save it |
| 49 | + IFS= |
| 50 | + echo "GO_VERSION=${norm[*]}" >> "$GITHUB_ENV" |
| 51 | + } |
| 52 | +
|
| 53 | + if [ "${{ inputs.strategy }}" == "canary" ]; then |
| 54 | + golang::canary |
| 55 | + elif [ "${{ inputs.strategy }}" == "latest-stable" ]; then |
| 56 | + echo "GO_VERSION=${{ inputs._stable }}" >> "$GITHUB_ENV" |
| 57 | + elif [ "${{ inputs.strategy }}" == "old-stable" ]; then |
| 58 | + echo "GO_VERSION=${{ inputs._old_stable }}" >> "$GITHUB_ENV" |
| 59 | + else |
| 60 | + echo "GO_VERSION=${{ inputs._current }}" >> "$GITHUB_ENV" |
| 61 | + fi |
| 62 | + - name: "Setup Go" |
| 63 | + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 |
| 64 | + with: |
| 65 | + go-version: ${{ env.GO_VERSION }} |
| 66 | + cache-dependency-path: ${{ inputs.cache-dependency-path }} |
| 67 | + cache: true |
| 68 | + - name: "Cleanup go version string" |
| 69 | + shell: bash |
| 70 | + # Remove possible trailing .x |
| 71 | + run: | |
| 72 | + echo "GO_VERSION=${GO_VERSION%.x*}" >> "$GITHUB_ENV" |
0 commit comments