-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
143 lines (128 loc) · 4.48 KB
/
action.yaml
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
name: Bump Stack LTS
description: |
Update a Stack-based Haskell project to latest LTS and open a Pull Request
with Changelog outlining the difference from current.
inputs:
stack-yaml:
description: "Path to stack.yaml"
required: true
default: stack.yaml
snapshot-yaml:
description: "Path to custom snapshot, if used"
required: false
working-directory:
description: "Directory for all run steps"
required: true
default: .
actor:
description: "Login to use instead of github.actor"
required: true
default: ""
github-repo:
description: "Repo in which snapshots are kept, e.g.: commercialhaskell/stackage-snapshots"
github-ref:
description: "Branch, commit, or tag of snapshot repo to use"
default: main
github-token:
description: "Override GitHub token, if necessary"
required: true
default: "${{ github.token }}"
outputs:
path:
description: "File being updated"
value: ${{ steps.setup.outputs.path }}
current:
description: "Current resolver"
value: ${{ steps.setup.outputs.current }}
latest:
description: "Latest LTS resolver"
value: ${{ steps.setup.outputs.latest }}
newer-available:
description: "True if we found a newer resolver"
value: ${{ steps.update.outputs.newer-available }}
build-errors:
description: "True if stack was not able to build"
value: ${{ steps.commit.outputs.build-errors }}
commit-message:
description: "Commit message used, including Changelog information"
value: ${{ steps.commit.outputs.message }}
runs:
using: composite
steps:
- name: Setup
id: setup
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
gh_repo=${{ inputs.github-repo }}
gh_ref=${{ inputs.github-ref }}
if [ -n "${{ inputs.snapshot-yaml }}" ]; then
path=${{ inputs.snapshot-yaml }}
else
path=${{ inputs.stack-yaml }}
fi
echo "path=$path" >>"$GITHUB_OUTPUT"
current=$(sed '/^resolver: \(.*\)$/!d; s//\1/' "$path")
echo "current=$current" >>"$GITHUB_OUTPUT"
if [[ -z "$gh_repo" ]]; then
latest=$(
curl --silent -D - https://www.stackage.org/lts |
sed '/^location: \/\(.*\)/!d; s//\1/;' |
tr '\r\n' '\n'
)
else
latest_version=$(
gh api "/repos/$gh_repo/git/trees/$gh_ref?recursive=true" -q '.tree[]|.path' |
sort -rV |
head -n 1
)
latest="https://raw.githubusercontent.com/$gh_repo/$gh_ref/$latest_version"
fi
echo "latest=$latest" >>"$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ inputs.github-token }}
- name: Update resolver
id: update
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
current=${{ steps.setup.outputs.current }}
latest=${{ steps.setup.outputs.latest }}
path=${{ steps.setup.outputs.path }}
if [[ "$current" == "$latest" ]]; then
echo "Up to date ($current)"
echo "newer-available=false" >>"$GITHUB_OUTPUT"
exit 0
fi
echo "newer-available=true" >>"$GITHUB_OUTPUT"
sed -i 's|^resolver: .*$|resolver: '"$latest"'|' "$path"
- if: ${{ steps.update.outputs.newer-available == 'true' }}
name: Build and commit
id: commit
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
current=${{ steps.setup.outputs.current }}
latest=${{ steps.setup.outputs.latest }}
stack_yaml=${{ inputs.stack-yaml }}
stack_yaml_lock=${{ inputs.stack-yaml }}.lock
path=${{ steps.setup.outputs.path }}
if ! stack build --dry-run --test --bench --stack-yaml "$stack_yaml" ; then
echo "build-errors=true" >>"$GITHUB_OUTPUT"
fi
commit_message() {
cat <<EOM
Bump Stackage Resolver to $latest
See here for changed packages:
https://www.stackage.org/diff/$current/$latest
EOM
}
actor=${{ inputs.actor }}
actor=${actor:-${{ github.actor }}}
git config --global user.email "[email protected]"
git config --global user.name "$actor"
git commit "$stack_yaml" "$stack_yaml_lock" "$path" --file <(commit_message)
delimiter="$(openssl rand -hex 8)"
echo "message<<${delimiter}" >> $GITHUB_OUTPUT
commit_message >> $GITHUB_OUTPUT
echo "${delimiter}" >> $GITHUB_OUTPUT