-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (133 loc) · 4.82 KB
/
build-container.yml
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
name: Build containers
on:
schedule:
- cron: '10 4 * * *'
workflow_dispatch:
inputs:
force_rebuild:
required: true
default: 'false'
dc:
required: false
version:
required: false
jobs:
build:
# Prevent from building in cloned repos
if: github.repository_owner == 'tom-tan'
strategy:
matrix:
dc: [dmd, ldc, gdc]
include:
- dc: dmd
arch: linux/amd64
- dc: ldc
arch: linux/amd64,linux/arm64
- dc: gdc
arch: linux/amd64
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- run: echo "RANDOM_SUFFIX=${RANDOM}" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ${{ github.workspace }}/dc-versions
key: ${{ matrix.dc }}-${{ env.RANDOM_SUFFIX }}
restore-keys: |
${{ matrix.dc }}-
- id: get_release
run: |
if [ "${dc}" = dmd ]; then
link=http://downloads.dlang.org/releases/LATEST
elif [ "${dc}" = ldc ]; then
link=https://ldc-developers.github.io/LATEST
elif [ "${dc}" = gdc ]; then
link=https://gdcproject.org/downloads/LATEST
else
echo "::error ::unknown 'dc': ${dc}"
return 1
fi
latest=$(curl --connect-timeout 10 -fsSL $link)
if [ -e $GITHUB_WORKSPACE/dc-versions/$dc ]; then
cur="$(cat $GITHUB_WORKSPACE/dc-versions/$dc)"
else
cur=""
fi
if [ "$force_rebuild" = "true" ]; then
if [ -z "$specified_dc" -o "$specified_dc" = "${dc}" ]; then
if [ -n "$specified_dc" -a -z "$specified_ver" ]; then
echo "::error ::'dc' is specified but 'version' is not"
return 1
elif [ -z "$specified_dc" -a -n "$specified_ver" ]; then
echo "::error ::'dc' is not specified but 'version' is"
return 1
fi
need_update=true
target_ver="$specified_ver"
else
need_update=false
latest=""
fi
elif [ -z "$latest" -o "$latest" = "$cur" ]; then
need_update=false
latest=""
else
need_update=true
target_ver="$latest"
fi
echo "need_update=$need_update" >> $GITHUB_OUTPUT
echo "latest=$latest" >> $GITHUB_OUTPUT
echo "target_ver=$target_ver" >> $GITHUB_OUTPUT
echo "need_update? '$need_update', current: '$cur', latest: '$latest', target: '$target_ver'"
env:
dc: ${{ matrix.dc }}
force_rebuild: ${{ github.event.inputs.force_rebuild }}
specified_dc: ${{ github.event.inputs.dc }}
specified_ver: ${{ github.event.inputs.version }}
- name: Set up QEMU
if: steps.get_release.outputs.need_update == 'true'
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
if: steps.get_release.outputs.need_update == 'true'
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
if: steps.get_release.outputs.need_update == 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: generate latest image name
id: image_names
run: |
if [ "${{steps.get_release.outputs.target_ver}}" = "${{steps.get_release.outputs.latest}}" ]; then
echo "latest_image=ghcr.io/${{ github.repository_owner }}/${{ matrix.dc }}:latest" >> $GITHUB_OUTPUT
else
echo "latest_image=" >> $GITHUB_OUTPUT
fi
- name: Build and push
if: steps.get_release.outputs.need_update == 'true'
uses: docker/build-push-action@v3
with:
context: .
file: .devcontainer/Dockerfile
platforms: ${{ matrix.arch }}
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.dc }}:${{ steps.get_release.outputs.target_ver }}
${{ steps.image_names.outputs.latest_image }}
build-args: |
VARIANT=ubuntu-22.04
DC_NAME=${{ matrix.dc }}
DC_VERSION=${{ steps.get_release.outputs.target_ver }}
- name: Cache latest version info
if: steps.get_release.outputs.need_update == 'true' && steps.get_release.outputs.target_ver == steps.get_release.outputs.latest
run: |
mkdir -p $GITHUB_WORKSPACE/dc-versions
echo $latest > $GITHUB_WORKSPACE/dc-versions/$dc
env:
dc: ${{ matrix.dc }}
latest: ${{ steps.get_release.outputs.latest }}