-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (140 loc) · 4.92 KB
/
build.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
name: Build
on:
# push:
# branches:
# - main
pull_request:
branches:
- main
types:
- closed
- opened
- reopened
- synchronize
- auto_merge_enabled
schedule:
- cron: '00 02 1 * *'
workflow_dispatch: {}
jobs:
builds:
name: WSL2 build
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
packages: write
env:
COMMIT_SHORT_SHA: null
steps:
- name: Checkout from repository
uses: actions/[email protected]
- name: Set short git commit SHA
run: |+
set -eux
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/naa0yama/devtool-wsl2
flavor: |
latest=false
tags: |
type=ref,event=tag,prefix=,enable=true
# minimal (short sha)
type=sha,enable=true,prefix=,format=short
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/[email protected]
with:
context: .
file: Dockerfile
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=tar,dest=dwsl2-${{ env.COMMIT_SHORT_SHA }}.tar
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Cleanup pre-releases
uses: actions/[email protected]
if: ${{ github.event.pull_request.merged == true }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |+
const __prereleases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const prereleases = __prereleases.data
for (const index in prereleases) {
if (prereleases[index].prerelease == true) {
console.log('delte pre-release ' + prereleases[index]['id'] + '\t' + prereleases[index]['name'])
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: prereleases[index]['id'],
});
}
}
console.log('end run')
- name: Split archive file.
if: ${{ github.event.pull_request.merged == true }}
run: |+
set -eux
mkdir -p dist
gzip "dwsl2-${{ env.COMMIT_SHORT_SHA }}.tar"
split --verbose --bytes=2000M --suffix-length=1 --numeric-suffixes=1 \
dwsl2-${{ env.COMMIT_SHORT_SHA }}.tar.gz \
dist/dwsl2-${{ env.COMMIT_SHORT_SHA }}.tar.gz.part
- name: Calculate the sha256sum
if: ${{ github.event.pull_request.merged == true }}
working-directory: dist
run: |+
set -eux
sha256sum dwsl2-${{ env.COMMIT_SHORT_SHA }}.tar.gz.part* > sha256sum.txt
ls -lah .
- name: Determine if PR is from a bot
id: check_bot
run: |
if [[ "${{ github.actor }}" == *[bot]* ]]; then
echo "IS_BOT=true" >> $GITHUB_ENV
else
echo "IS_BOT=false" >> $GITHUB_ENV
fi
- name: Determine release type
id: release_type
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "DRAFT=false" >> $GITHUB_ENV
echo "MAKE_LATEST=true" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" != "closed" && "${{ env.IS_BOT }}" == "false" ]]; then
echo "DRAFT=true" >> $GITHUB_ENV
echo "MAKE_LATEST=false" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
echo "DRAFT=false" >> $GITHUB_ENV
echo "MAKE_LATEST=true" >> $GITHUB_ENV
else
echo "DRAFT=false" >> $GITHUB_ENV
echo "MAKE_LATEST=false" >> $GITHUB_ENV
fi
- name: Pre-Release
uses: softprops/action-gh-release@v2
if: ${{ github.event.pull_request.merged == true }}
with:
name: devtool-WSL2 image ${{ env.COMMIT_SHORT_SHA }}
tag_name: ${{ env.COMMIT_SHORT_SHA }}
generate_release_notes: true
draft: ${{ env.DRAFT }}
prerelease: false
make_latest: ${{ env.MAKE_LATEST }}
files: |
./dist/*