Skip to content

Commit 9f7a804

Browse files
committed
First crack at a GitHub Actions workflow
1 parent a066310 commit 9f7a804

File tree

5 files changed

+88
-7
lines changed

5 files changed

+88
-7
lines changed

.github/workflows/ghcup.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "`ghcup` image"
2+
3+
on:
4+
# FIXME: Remove this before merging!
5+
pull_request: { branches: [ "master" ] }
6+
push: { branches: [ "release" ] }
7+
8+
env:
9+
alpine_ver: "3.14"
10+
11+
jobs:
12+
build:
13+
runs-on: "ubuntu-20.04"
14+
15+
strategy:
16+
matrix:
17+
ghc_ver: [ "8.10.7" ]
18+
numeric: [ "gmp" ]
19+
20+
steps:
21+
- name: "Check this repository out."
22+
uses: "actions/checkout@v2"
23+
24+
- name: "Build `ghcup` image."
25+
id: "build-ghcup-image"
26+
run: |
27+
image=$(
28+
./ghcup/builder.sh \
29+
-a "${{ env.alpine_ver }}" \
30+
-g "${{ matrix.ghc_ver }}" \
31+
-n "${{ matrix.numeric }}" \
32+
| tail -n 1
33+
)
34+
echo "::set-output name=image::${image}"
35+
36+
- name: "Push `ghcup` image to the GitHub Container Registry"
37+
id: "push-ghcup-to-ghcr"
38+
uses: "redhat-actions/push-to-registry@v2"
39+
with:
40+
image: "${{ steps.build-ghcup-image.outputs.image }}"
41+
username: "${{ github.actor }}"
42+
password: "${{ github.token }}"
43+
registry: "ghcr.io/${{ github.repository_owner }}"
44+
45+
- name: "Print image URL."
46+
run: |
47+
echo "Image pushed to [ ${{ steps.push-ghcup-to-ghcr.outputs.registry-paths }} ]"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.direnv
2+
tmp

ghc/builder.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ alpine_ver="3.14"
2121
container="ghc"
2222
image="ghc"
2323
ghc_ver="8.10.7"
24+
2425
# NOTE: The logic associated with this will have to change for GHC 9.x and up to
2526
# support the changes introduced with the switch to `ghc-bignum`.
2627
numeric="gmp"
@@ -33,7 +34,7 @@ usage="USAGE: $0
3334
default: ${container}
3435
-g GHC_VER override the numeric library GHC is built against; either 'gmp' or 'simple'
3536
default: ${ghc_ver}
36-
-i IMAGE override the default image name
37+
-i IMAGE override the default image base name
3738
default: ${image}
3839
-n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'simple'
3940
default: ${numeric}"
@@ -172,10 +173,32 @@ buildah run "${container}" \
172173
buildah run "${container}" \
173174
rm -rf "/tmp/{build.mk,compile_ghc.sh,patches}"
174175

176+
# Add `ghcup`'s bin directory to the container's `PATH`.
177+
#
178+
# NOTE: This little bit of indirection is needed to get the container's 'PATH',
179+
# since '$PATH' would be sourced from the host.
180+
cntr_path=$(buildah run "${container}" printenv PATH)
181+
buildah config \
182+
--env PATH="${cntr_path}:/root/.ghcup/bin" \
183+
"${container}"
184+
175185
################################################################################
176186
# Generate the final image.
177187
################################################################################
178188

189+
# NOTE: `buildah` uses `/var/tmp` (or $TMPDIR) as a staging area when assembling
190+
# images.
191+
#
192+
# On systems where `/var/tmp` is mounted as `tmpfs`, this can cause `buildah` to
193+
# run out of space.
194+
#
195+
# In this case, create some `./tmp` directory and use it with `TMPDIR=./tmp`
196+
# before running `buildah commit`.
197+
#
198+
# e.g. Uncomment the following:
199+
#
200+
# mkdir -p ./tmp
201+
# TMPDIR=./tmp \
179202
buildah \
180203
--signature-policy=./policy.json \
181204
commit --rm "${container}" "${image}"

ghcup/builder.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ container="ghcup"
2222
image="ghcup"
2323

2424
usage="USAGE: $0
25-
-h show this help text
25+
-h show this help text
2626
-a ALPINE_VER override the default Alpine version
2727
default: ${alpine_ver}
28-
-c CONTAINER override the default container name
29-
default: ${container}
30-
-i IMAGE override the default image name
28+
-c CONTAINER override the default container name
29+
default: ${container}
30+
-i IMAGE override the default image base name
3131
default: ${image}"
3232

3333
while getopts "a:c:i:h" opt; do
@@ -106,14 +106,23 @@ buildah run "${container}" \
106106
buildah run "${container}" \
107107
mv /tmp/"ghcup-${ghcup_version}" /usr/bin/ghcup
108108

109-
# ...set it to be executable...
109+
# ...make it executable...
110110
buildah run "${container}" \
111111
chmod +x /usr/bin/ghcup
112112

113-
# ...clean up any scripts.
113+
# ...and clean up any scripts.
114114
buildah run "${container}" \
115115
rm -rf /tmp/validate_checksum.sh
116116

117+
# Add `ghcup`'s bin directory to the container's `PATH`.
118+
#
119+
# NOTE: This little bit of indirection is needed to get the container's 'PATH',
120+
# since '$PATH' would be sourced from the host.
121+
cntr_path=$(buildah run "${container}" printenv PATH)
122+
buildah config \
123+
--env PATH="${cntr_path}:/root/.ghcup/bin" \
124+
"${container}"
125+
117126
################################################################################
118127
# Generate the final image.
119128
################################################################################

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pkgs.mkShell {
66
skopeo
77

88
# Misc. other dependencies.
9+
jq
910
nixpkgs-fmt
1011
shellcheck
1112
];

0 commit comments

Comments
 (0)