Skip to content

Commit

Permalink
feat: add github action ci
Browse files Browse the repository at this point in the history
  • Loading branch information
yaokl committed Feb 19, 2024
1 parent 6e971cc commit 75284e4
Showing 1 changed file with 175 additions and 0 deletions.
175 changes: 175 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: Build

on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
- cron: '0 1 * * *'
workflow_dispatch:


jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build kubeadm
id: build_kubeadm
run: |
set -eux
APP=kubernetes
APP_VERSION=$(cat kube_version.txt)
APP_REPO="https://github.com/kubernetes/kubernetes.git"
ADD_TAG=""
tags="$(git ls-remote --tags $APP_REPO | grep 'v[1-9]\.[0-9]*\.[0-9]*$' | awk -F'tags/' '{print $2}' | sort -t. -k1,1n -k2,2n -k3,3n)"
new_tags="$(printf "%s" "$tags"| sed -n '{/\.0$/{g;p}};h' | tail -5) $(printf "%s" "$tags" | tail -1) v1.21.10 v1.22.7 v1.23.4"
echo -e "[Tags] $new_tags"
mkdir -p $GOPATH/src/k8s.io && cd $GOPATH/src/k8s.io
for t in $new_tags; do
echo "[check] $t"
b=$(echo "${APP_VERSION}" | grep -w ${t} | wc -l)
if [[ $b == 0 ]]; then
echo "::group::[Build] $t"
git clone -q --depth=1 --branch $t --progress "${APP_REPO}"
pushd ${APP}
git checkout -b $t $t
git branch
sed -i 's#time.Hour \* 24 \* 365#time.Hour * 24 * 365 * 10#g' cmd/kubeadm/app/constants/constants.go
grep -n -R CertificateValidity ./*
grep -n -R duration365d ./*
build_version=$(cat build/build-image/cross/VERSION)
docker pull registry.k8s.io/build-image/kube-cross:${build_version}
./build/run.sh make kubeadm KUBE_BUILD_PLATFORMS=linux/amd64 >/dev/null
ls -l _output/dockerized/bin/linux/amd64/
./build/run.sh make kubeadm KUBE_BUILD_PLATFORMS=linux/386 >/dev/null
ls -l _output/dockerized/bin/linux/amd64/
cp _output/dockerized/bin/linux/386/kubeadm _output/kubeadm-linux-386 || return 1
cp _output/dockerized/bin/linux/amd64/kubeadm _output/kubeadm-linux-amd64 || return 1
ls -al _output/kubeadm-*
_output/kubeadm-linux-386 version
_output/kubeadm-linux-amd64 version
md5sum _output/kubeadm-linux-386 > _output/kubeadm-linux-386.md5 && sha256sum _output/kubeadm-linux-386 > _output/kubeadm-linux-386.sha256
md5sum _output/kubeadm-linux-amd64 > _output/kubeadm-linux-amd64.md5 && sha256sum _output/kubeadm-linux-amd64 > _output/kubeadm-linux-amd64.sha256
echo "::debug::[certs] test"
sudo _output/kubeadm-linux-amd64 init phase certs all
sudo _output/kubeadm-linux-amd64 init phase kubeconfig all
sudo _output/kubeadm-linux-amd64 certs check-expiration || sudo _output/kubeadm-linux-amd64 alpha certs check-expiration
ADD_TAG=$t
echo "[ADD_TAG] ${ADD_TAG}"
[[ "x${ADD_TAG:-}" == "x" ]] && return 1 || echo ok
echo "::debug::[Push file]"
echo "${ADD_TAG}" >> kube_version.txt
git config --global user.email "[email protected]"
git config --global user.name "lework"
git remote rm origin
git remote add origin https://${GITHUB_TOKEN}@github.com/lework/kubeadm-certs.git > /dev/null 2>&1
git add -A
git commit -m "add kubeadm $kube_tag"
git push origin master
git config --global user.email "[email protected]"
git config --global user.name "lework"
git config --global --add safe.directory /github/workspace
git add version.txt
git commit -m "add kubeadm $ADD_TAG (Github Actions Automatically Built in `date +"%Y-%m-%d %H:%M"`)"
echo "ADD_TAG=${ADD_TAG}" >> $GITHUB_OUTPUT
cat _output/kubeadm-linux-{amd64,386}.{md5,sha256} > CHECKSUMS.txt
echo "::endgroup::"
popd
break
break
else
echo "[skip] $t"
fi
one

for t in $new_tags; do
echo "[check] $t"
b=$(echo "${APP_VERSION}" | grep -w ${t} | wc -l)
if [[ $b == 0 ]]; then
echo "::group::[Build] $t"
git clone -q --depth=1 --branch $t --progress $APP_REPO
pushd ${APP}
git checkout -b $t $t
git branch

# golang:1.19.2-alpine3.16
docker pull golang:1.19.2-alpine3.16
# Linux builds
docker run --rm -t -v $PWD:/build golang:1.19.2-alpine3.16 sh -c "apk update && apk add gpgme btrfs-progs-dev llvm13-dev gcc musl-dev && cd /build && CGO_ENABLE=0 GO111MODULE=on GOOS=linux GOARCH=amd64 go build -mod=vendor '-buildmode=pie' -ldflags '-extldflags -static' -gcflags '' -tags 'exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp' -o ./bin/skopeo-linux-amd64 ./cmd/skopeo && md5sum ./bin/skopeo-linux-amd64 > ./bin/skopeo-linux-amd64.md5 && sha256sum ./bin/skopeo-linux-amd64 > ./bin/skopeo-linux-amd64.sha256"

docker run --rm -t -v $PWD:/build golang:1.19.2-alpine3.16 sh -c "apk update && apk add gpgme btrfs-progs-dev llvm13-dev gcc musl-dev && cd /build && CGO_ENABLE=0 GO111MODULE=on GOOS=linux GOARCH=arm64 go build -mod=vendor '-buildmode=pie' -ldflags '-extldflags -static' -gcflags '' -tags 'exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp' -o ./bin/skopeo-linux-arm64 ./cmd/skopeo && md5sum ./bin/skopeo-linux-arm64 > ./bin/skopeo-linux-arm64.md5 && sha256sum ./bin/skopeo-linux-arm64 > ./bin/skopeo-linux-arm64.sha256"

# Darwin builds
docker run --rm -t -v $PWD:/build golang:1.19.2-alpine3.16 sh -c "apk update && apk add gpgme btrfs-progs-dev llvm13-dev gcc musl-dev && cd /build && CGO_ENABLE=0 GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -mod=vendor -gcflags '' -tags 'exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp' -o ./bin/skopeo-darwin-amd64 ./cmd/skopeo && md5sum ./bin/skopeo-darwin-amd64 > ./bin/skopeo-darwin-amd64.md5 && sha256sum ./bin/skopeo-darwin-amd64 > ./bin/skopeo-darwin-amd64.sha256"

docker run --rm -t -v $PWD:/build golang:1.19.2-alpine3.16 sh -c "apk update && apk add gpgme btrfs-progs-dev llvm13-dev gcc musl-dev && cd /build && CGO_ENABLE=0 GO111MODULE=on GOOS=darwin GOARCH=arm64 go build -mod=vendor -gcflags '' -tags 'exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp' -o ./bin/skopeo-darwin-arm64 ./cmd/skopeo && md5sum ./bin/skopeo-darwin-arm64 > ./bin/skopeo-darwin-arm64.md5 && sha256sum ./bin/skopeo-darwin-arm64 > ./bin/skopeo-darwin-arm64.sha256"
ls -al bin/
cd ../
ls -al ./
ADD_TAG=$t

echo "::debug::[Push file]"
echo "${t}" >> version.txt
git config --global user.email "[email protected]"
git config --global user.name "lework"
git config --global --add safe.directory /github/workspace
git add version.txt
git commit -m "$APP $ADD_TAG (Github Actions Automatically Built in `date +"%Y-%m-%d %H:%M"`)"
echo "ADD_TAG=${ADD_TAG}" >> $GITHUB_OUTPUT
cat ./skopeo/bin/skopeo-{darwin,linux}-{amd64,arm64}.{md5,sha256} > CHECKSUMS.txt
echo "::endgroup::"
popd
break
else
echo "::debug::[skip] $t"
fi
done
- name: Push changes
uses: ad-m/github-push-action@master
if: ${{ steps.build_skopeo.outputs.ADD_TAG != '' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Release
uses: softprops/action-gh-release@v1
if: ${{ steps.build_skopeo.outputs.ADD_TAG != '' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: "${{ steps.build_skopeo.outputs.ADD_TAG }}"
files: |
./skopeo/bin/skopeo-linux-amd64
./skopeo/bin/skopeo-linux-amd64.md5
./skopeo/bin/skopeo-linux-amd64.sha256
./skopeo/bin/skopeo-linux-arm64
./skopeo/bin/skopeo-linux-arm64.md5
./skopeo/bin/skopeo-linux-arm64.sha256
./skopeo/bin/skopeo-darwin-amd64
./skopeo/bin/skopeo-darwin-amd64.md5
./skopeo/bin/skopeo-darwin-amd64.sha256
./skopeo/bin/skopeo-darwin-arm64
./skopeo/bin/skopeo-darwin-arm64.md5
./skopeo/bin/skopeo-darwin-arm64.sha256
body_path: ./CHECKSUMS.txt

0 comments on commit 75284e4

Please sign in to comment.