-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
148 lines (138 loc) · 4.62 KB
/
action.yml
File metadata and controls
148 lines (138 loc) · 4.62 KB
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
138
139
140
141
142
143
144
145
146
147
148
name: "IfChange (slnc)"
description: Enforce LINT.IfChange/ThenChange directives in pull requests
branding:
icon: check-circle
color: green
# LINT.IfChange("inputs")
inputs:
version:
description: "Release tag to install (e.g. v1.0.0). Empty means latest."
required: false
default: ""
args:
description: "Extra arguments passed to ifchange"
required: false
default: ""
diff:
description: "Path to a pre-built diff file. If empty, the action generates one."
required: false
default: ""
token:
description: "GitHub token for downloading release assets"
required: false
default: ${{ github.token }}
# LINT.ThenChange([
# "README.md#action",
# "examples/README.md#action",
# "examples/workflows/ifchange.yml",
# ".github/workflows/ci.yml",
# ])
runs:
using: composite
steps:
- name: Check for existing binary
id: check
shell: bash
run: |
if command -v ifchange &>/dev/null; then
echo "found=true" >> "$GITHUB_OUTPUT"
echo "ifchange already on PATH: $(which ifchange)"
else
echo "found=false" >> "$GITHUB_OUTPUT"
fi
- name: Detect platform
if: steps.check.outputs.found == 'false'
id: platform
shell: bash
env:
RUNNER_OS_ARCH: ${{ runner.os }}-${{ runner.arch }}
run: |
case "$RUNNER_OS_ARCH" in
Linux-X64) target="x86_64-unknown-linux-gnu" ; ext="tar.gz" ;;
Linux-ARM64) target="aarch64-unknown-linux-gnu" ; ext="tar.gz" ;;
macOS-ARM64) target="aarch64-apple-darwin" ; ext="tar.gz" ;;
macOS-X64) target="x86_64-apple-darwin" ; ext="tar.gz" ;;
Windows-X64) target="x86_64-pc-windows-msvc" ; ext="zip" ;;
*) echo "::error::Unsupported platform: $RUNNER_OS_ARCH" ; exit 1 ;;
esac
echo "target=$target" >> "$GITHUB_OUTPUT"
echo "ext=$ext" >> "$GITHUB_OUTPUT"
- name: Resolve version
if: steps.check.outputs.found == 'false'
id: version
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
INPUT_VERSION: ${{ inputs.version }}
ACTION_REPO: ${{ github.action_repository || github.repository }}
run: |
if [[ -n "$INPUT_VERSION" ]]; then
echo "tag=$INPUT_VERSION" >> "$GITHUB_OUTPUT"
else
tag="$(gh api "/repos/$ACTION_REPO/releases/latest" --jq .tag_name)"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
fi
- name: Download and install binary
if: steps.check.outputs.found == 'false'
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
ACTION_REPO: ${{ github.action_repository || github.repository }}
VERSION: ${{ steps.version.outputs.tag }}
TARGET: ${{ steps.platform.outputs.target }}
EXT: ${{ steps.platform.outputs.ext }}
RUNNER_TEMP: ${{ runner.temp }}
run: |
set -euo pipefail
version="$VERSION"
target="$TARGET"
ext="$EXT"
archive="ifchange-${version}-${target}.${ext}"
gh release download "$version" \
--repo "$ACTION_REPO" \
--pattern "$archive" \
--dir "$RUNNER_TEMP"
cd "$RUNNER_TEMP"
if [[ "$ext" == "tar.gz" ]]; then
tar -xzf "$archive"
else
unzip -o "$archive"
fi
chmod +x ifchange* 2>/dev/null || true
mkdir -p "$HOME/.local/bin"
mv ifchange* "$HOME/.local/bin/"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Build diff
if: ${{ inputs.diff == '' }}
id: diff
shell: bash
env:
RUNNER_TEMP: ${{ runner.temp }}
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
EVENT_BEFORE: ${{ github.event.before }}
EVENT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
diff_file="${RUNNER_TEMP}/changes.diff"
if [[ "$EVENT_NAME" == "pull_request" ]]; then
git fetch origin "$BASE_REF" --depth=1 2>/dev/null || true
git diff --merge-base "origin/$BASE_REF" HEAD > "$diff_file"
else
git diff "$EVENT_BEFORE" "$EVENT_SHA" > "$diff_file"
fi
echo "path=$diff_file" >> "$GITHUB_OUTPUT"
- name: Run ifchange
shell: bash
env:
INPUT_ARGS: ${{ inputs.args }}
DIFF_FILE: ${{ inputs.diff || steps.diff.outputs.path }}
run: |
set -euo pipefail
diff_file="$DIFF_FILE"
args=()
if [[ -n "$INPUT_ARGS" ]]; then
# Split on shell whitespace without evaluating metacharacters.
read -r -a args <<< "$INPUT_ARGS"
fi
ifchange "${args[@]}" "$diff_file"