Skip to content

Commit 2e11991

Browse files
Dani Llewellynactions-user
authored andcommitted
Add sync, build, and release GitHub Actions workflows
Signed-off-by: Dani Llewellyn <diddledani@ubuntu.com>
1 parent a733b4e commit 2e11991

5 files changed

Lines changed: 280 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: 🏗️ Build new release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
snapd_tags:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
snapd_tag: ${{ fromJson(inputs.snapd_tags) }}
16+
arch:
17+
- x86_64
18+
- arm64
19+
steps:
20+
- name: Install dependencies
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -yqq \
24+
build-essential \
25+
bison \
26+
dwarves \
27+
flex \
28+
libelf-dev \
29+
gcc-aarch64-linux-gnu
30+
- name: Configrue build variables
31+
id: build_variables
32+
run: |
33+
case "${{ matrix.arch }}" in
34+
arm64)
35+
ARCH=arm64
36+
CROSS_COMPILE=aarch64-linux-gnu-
37+
IMAGE_NAME=Image.gz
38+
;;
39+
x86|x86_64)
40+
ARCH=x86
41+
CROSS_COMPILE=
42+
IMAGE_NAME=bzImage
43+
;;
44+
*)
45+
false
46+
;;
47+
esac
48+
49+
echo "::echo::on"
50+
echo "::set-output name=architecture::$ARCH"
51+
echo "::set-output name=build_output_filename::arch/$ARCH/boot/$IMAGE_NAME"
52+
echo "::set-output name=cross_compile::$CROSS_COMPILE"
53+
echo "::set-output name=release_asset_filename::vmlinux-wsl2-snapd-${{ matrix.arch }}"
54+
- uses: actions/checkout@v3
55+
with:
56+
ref: ${{ matrix.snapd_tag }}
57+
- name: Build ${{ matrix.snapd_tag }}:${{ matrix.arch }}
58+
id: build
59+
env:
60+
ARCH: ${{ steps.build_variables.outputs.architecture }}
61+
BUILD_OUTPUT_FILENAME: ${{ steps.build_variables.outputs.build_output_filename }}
62+
CROSS_COMPILE: ${{ steps.build_variables.outputs.cross_compile }}
63+
IMAGE_NAME: ${{ steps.build_variables.outputs.image_name }}
64+
RELEASE_ASSET_FILENAME: ${{ steps.build_variables.outputs.release_asset_filename }}
65+
run: |
66+
# Verify that the WSL configuration is present
67+
[ -f "arch/$ARCH/configs/wsl2_defconfig" ]
68+
69+
make ARCH="$ARCH" wsl2_defconfig snap_support.config
70+
make -j$(nproc) ARCH="$ARCH" ${CROSS_COMPILE:+CROSS_COMPILE=$CROSS_COMPILE}
71+
72+
cp -f "$BUILD_OUTPUT_FILENAME" "$RELEASE_ASSET_FILENAME"
73+
- name: Upload ${{ matrix.snapd_tag }}:${{ matrix.arch }}
74+
uses: softprops/action-gh-release@v1
75+
with:
76+
token: ${{ secrets.GITHUB_TOKEN }}
77+
draft: true
78+
name: Release ${{ matrix.snapd_tag }}
79+
tag_name: ${{ matrix.snapd_tag }}
80+
files: ${{ steps.build_variables.outputs.release_asset_filename }}

.github/workflows/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: ⚙️ Continuous Delivery
2+
3+
on:
4+
schedule:
5+
- cron: "0 * * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
trigger-sync:
10+
if: ${{ github.repository == 'diddlesnaps/WSL2-Linux-Kernel' }}
11+
uses: ./.github/workflows/sync-upstream.yml
12+
secrets: inherit
13+
14+
trigger-tagger:
15+
needs: trigger-sync
16+
if: ${{ needs.trigger-sync.outputs.missing_tags }}
17+
uses: ./.github/workflows/tag-release.yml
18+
secrets: inherit
19+
with:
20+
missing_tags: ${{ needs.trigger-sync.outputs.missing_tags }}
21+
22+
trigger-build:
23+
needs:
24+
- trigger-sync # need to expliticly add this to access the outputs
25+
- trigger-tagger
26+
if: ${{ needs.trigger-sync.outputs.snapd_tags }}
27+
uses: ./.github/workflows/build-release.yml
28+
secrets: inherit
29+
with:
30+
snapd_tags: ${{ needs.trigger-sync.outputs.snapd_tags }}
31+
32+
trigger-publish:
33+
needs:
34+
- trigger-sync # need to expliticly add this to access the outputs
35+
- trigger-build
36+
if: ${{ always() && needs.trigger-sync.outputs.snapd_tags }}
37+
uses: ./.github/workflows/publish-release.yml
38+
secrets: inherit
39+
with:
40+
snapd_tags: ${{ needs.trigger-sync.outputs.snapd_tags }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 🚀 Publish release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
snapd_tags:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
publish_or_cleanup:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
snapd_tag: ${{ fromJson(inputs.snapd_tags) }}
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Publish release ${{ matrix.snapd_tag }}
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
[ "$(gh release view "${{ matrix.snapd_tag }}" --repo "${{ github.repository }}" --json assets --template '{{len .assets}}')" -gt 0 ]
23+
gh release edit "${{ matrix.snapd_tag }}" --repo "${{ github.repository }}" --draft=false
24+
- name: Remove failed release ${{ matrix.snapd_tag }}
25+
if: ${{ failure() || cancelled() }}
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
SNAPD_TAG: ${{ matrix.snapd_tag }}
29+
run: |
30+
UPSTREAM_TAG="${SNAPD_TAG/linux-msft-snapd-/linux-msft-wsl-}"
31+
gh release delete "$SNAPD_TAG" --repo "${{ github.repository }}" || true
32+
git push origin ":refs/tags/$SNAPD_TAG" || true
33+
git push origin ":refs/tags/$UPSTREAM_TAG" || true
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 🔄 Sync with upstream
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
missing_tags:
7+
description: The upstream tags that are missing locally
8+
value: ${{ jobs.sync_upstream.outputs.missing_tags }}
9+
snapd_tags:
10+
description: The new tags that we need to create
11+
value: ${{ jobs.sync_upstream.outputs.snapd_tags }}
12+
13+
jobs:
14+
sync_upstream:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Install dependencies
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -yyq jq
21+
- uses: actions/checkout@v3
22+
- name: Configure GIT
23+
run: |
24+
git config user.email 'actions@github.com'
25+
git config user.name 'GitHub Actions'
26+
git remote add upstream https://github.com/microsoft/WSL2-Linux-Kernel.git
27+
- name: Sync from upstream
28+
run: |
29+
git fetch --tags origin
30+
git fetch --tags --prune --progress --no-recurse-submodules upstream +refs/heads/master*:refs/remotes/upstream/master*
31+
- name: Parse upstream tags
32+
id: parse_tags
33+
run: |
34+
set -x
35+
36+
REMOTE_TAGS="$(git show-ref --tags | awk '{print $2}' | cut -d/ -f3 | grep '^linux-msft-wsl-' || true)"
37+
ORIGIN_TAGS="$(git ls-remote --tags origin | grep -v '\^{}' | cut -f2 | cut -d/ -f3 | grep '^linux-msft-wsl-' || true)"
38+
39+
MISSING_TAGS="$(echo "$REMOTE_TAGS" | grep -v -F "$ORIGIN_TAGS" || true)"
40+
41+
FILTERED_UPSTREAM_TAGS=()
42+
FILTERED_SNAPD_TAGS=()
43+
44+
for UPSTREAM_TAG in $MISSING_TAGS; do
45+
# check that we have a non-empty string
46+
[ -n "$UPSTREAM_TAG" ] || continue
47+
48+
# check that the tag name matches the format we're expecting
49+
echo "$UPSTREAM_TAG" | grep -Eq '^linux-msft-wsl-([0-9]+\.[0-9]+).*$' || continue
50+
51+
# check that we haven't already built this tag
52+
SNAPD_TAG="${UPSTREAM_TAG/linux-msft-wsl-/linux-msft-snapd-}"
53+
[ -z "$(git tag -l "$SNAPD_TAG")" ] || continue
54+
55+
FILTERED_UPSTREAM_TAGS+=($UPSTREAM_TAG)
56+
FILTERED_SNAPD_TAGS+=($SNAPD_TAG)
57+
done
58+
59+
echo '::echo::on'
60+
if [ "${#FILTERED_UPSTREAM_TAGS[@]}" -gt 0 ]; then
61+
echo "::set-output name=missing_tags::$(jq --compact-output --null-input '$ARGS.positional' --args -- "${FILTERED_UPSTREAM_TAGS[@]}")"
62+
echo "::set-output name=snapd_tags::$(jq --compact-output --null-input '$ARGS.positional' --args -- "${FILTERED_SNAPD_TAGS[@]}")"
63+
else
64+
echo "::set-output name=missing_tags::"
65+
echo "::set-output name=snapd_tags::"
66+
fi
67+
- name: Rebase and push master; push tags
68+
run: |
69+
git rebase upstream/master
70+
git push --force origin master
71+
git push --force --tags origin
72+
outputs:
73+
missing_tags: ${{ steps.parse_tags.outputs.missing_tags }}
74+
snapd_tags: ${{ steps.parse_tags.outputs.snapd_tags }}

.github/workflows/tag-release.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: 🏷️ Re-tag new upstream release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
missing_tags:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
tag-release:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
upstream_tag: ${{ fromJson(inputs.missing_tags) }}
16+
steps:
17+
- name: Build Variables
18+
id: build_variables
19+
env:
20+
UPSTREAM_TAG: ${{ matrix.upstream_tag }}
21+
run: |
22+
# Work out which snapd-support branch we need to merge
23+
SNAPD_TAG="${UPSTREAM_TAG/linux-msft-wsl-/linux-msft-snapd-}"
24+
RELEASE_MINOR_VER="$(echo "$UPSTREAM_TAG" | sed -Ee 's/^linux-msft-wsl-([0-9]+\.[0-9]+).*$/\1/')"
25+
26+
echo '::echo::on'
27+
echo "::set-output name=snapd_support_branch::snapd-support-$RELEASE_MINOR_VER.y"
28+
echo "::set-output name=snapd_tag::$SNAPD_TAG"
29+
- uses: actions/checkout@v3
30+
with:
31+
ref: ${{ matrix.upstream_tag }}
32+
fetch-depth: 0
33+
- name: Configure GIT
34+
run: |
35+
git config user.email 'actions@github.com'
36+
git config user.name 'GitHub Actions'
37+
git remote add upstream https://github.com/microsoft/WSL2-Linux-Kernel.git
38+
- name: Tag new release
39+
run: |
40+
set -x
41+
42+
# Merge the snapd-support branch
43+
git fetch --no-tags --prune --progress --no-recurse-submodules origin +refs/heads/"${{ steps.build_variables.outputs.snapd_support_branch }}"*:refs/remotes/origin/"${{ steps.build_variables.outputs.snapd_support_branch }}"*
44+
git merge --no-edit "origin/${{ steps.build_variables.outputs.snapd_support_branch }}"
45+
46+
# Tag the new release
47+
git tag -f "${{ steps.build_variables.outputs.snapd_tag }}"
48+
git push --tags --force
49+
- name: Failure or cancellation cleanup
50+
if: ${{ failure() || cancelled() }}
51+
run: |
52+
git push origin ":refs/tags/${{ steps.build_variables.outputs.snapd_tag }}" || true
53+
git push origin ":refs/tags/${{ matrix.upstream_tag }}" || true

0 commit comments

Comments
 (0)