add actions

This commit is contained in:
syui 2024-02-12 10:18:52 +09:00
parent b90fcbdd0d
commit f1602378f7
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
3 changed files with 129 additions and 26 deletions

53
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,53 @@
name: release
on:
push:
branches:
- main
schedule:
- cron: '0 0 * * *'
permissions:
contents: write
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
container:
image: archlinux
options: --privileged
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialize
run: |
pacman -Syuu --noconfirm base-devel archiso docker git
git clone https://gitlab.archlinux.org/archlinux/archiso
cp -rf ./cfg/profiledef.sh /usr/share/archiso/configs/releng/
cp -rf ./cfg/profiledef.sh ./archiso/configs/releng/profiledef.sh
cp -rf ./cfg/profiledef.sh ./archiso/configs/baseline/profiledef.sh
cp -rf ./scpt/mkarchiso ./archiso/archiso/mkarchiso
./archiso/archiso/mkarchiso -v -o ./ ./archiso/configs/releng/
tar xf aios-bootstrap*.tar.gz
echo -e 'Server = http://mirrors.cat.net/archlinux/$repo/os/$arch\nServer = https://geo.mirror.pkgbuild.com/$repo/os/$arch' >> ./root.x86_64/etc/pacman.d/mirrorlist
sed -i s/CheckSpace/#CheckeSpace/ root.x86_64/etc/pacman.conf
arch-chroot root.x86_64 /bin/sh -c 'pacman-key --init'
arch-chroot root.x86_64 /bin/sh -c 'pacman-key --populate archlinux'
arch-chroot root.x86_64 /bin/sh -c 'pacman -Syu --noconfirm base base-devel linux vim git zsh rust openssh openssl jq'
arch-chroot root.x86_64 /bin/sh -c 'git clone https://git.syui.ai/ai/bot && cd bot && cargo build && cp -rf ./target/debug/ai /bin/ && ai ai'
tar -zcvf aios-bootstrap.tar.gz root.x86_64/
tar -C ./root.x86_64 -c . | docker import - syui/aios
echo "${{ env.DOCKER_TOKEN }}" | docker login -u syui --password-stdin
docker push syui/aios
- name: Create new release
uses: softprops/action-gh-release@v1
with:
name: latest
tag_name: latest
files:
aios-bootstrap.tar.gz

View File

@ -58,3 +58,62 @@ cargo 1.75.0
``` ```
### gh-actions
https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
https://docs.github.com/en/enterprise-cloud@latest/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions
```yml
name: Demo Push
on:
push:
branches:
- main
- seed
tags:
- v*
pull_request:
This workflow runs when any of the following occur:
A push is made to a branch called main or seed
A tag starting with "v" is created
A pull request is created or updated
env:
IMAGE_NAME: ghtoken_product_demo
This creates an environment variable called IMAGE_NAME with the value ghtoken_product_demo.
jobs:
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
This pushes the image to GitHub Packages.
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
This changes all uppercase characters to lowercase.
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
This strips the git ref prefix from the version.
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
This strips the "v" prefix from the tag name.
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
```

View File

@ -1,30 +1,22 @@
#!/bin/zsh #!/bin/zsh
d=${0:a:h} d=${0:a:h}
case $1 in cd $d
bsae)
a=baseline
;;
*)
a=releng
;;
esac
if ! ls ./*.tar.gz;then
if ! ls $d/*.tar.gz;then rm -rf ./*.tar.gz
rm -rf $d/*.tar.gz
fi fi
if [ -d $d/work ];then if [ -d ./work ];then
rm -rf $d/work rm -rf ./work
fi fi
if [ -d $d/root.x86_64 ];then if [ -d ./root.x86_64 ];then
rm -rf $d/root.x86_64 rm -rf ./root.x86_64
fi fi
if [ -d $d/archiso ];then if [ -d ./archiso ];then
rm -rf $d/archiso rm -rf ./archiso
fi fi
git clone https://gitlab.archlinux.org/archlinux/archiso git clone https://gitlab.archlinux.org/archlinux/archiso
@ -32,13 +24,15 @@ git clone https://gitlab.archlinux.org/archlinux/archiso
# rm -rf $d/archlinux-docker # rm -rf $d/archlinux-docker
# git clone https://gitlab.archlinux.org/archlinux/archlinux-docker # git clone https://gitlab.archlinux.org/archlinux/archlinux-docker
cp -rf $d/cfg/profiledef.sh $d/archiso/configs/$a/profiledef.sh cp -rf ./cfg/profiledef.sh /usr/share/archiso/configs/releng/
cp -rf $d/scpt/mkarchiso $d/archiso/archiso/mkarchiso cp -rf ./cfg/profiledef.sh ./archiso/configs/releng/profiledef.sh
cp -rf ./cfg/profiledef.sh ./archiso/configs/baseline/profiledef.sh
cp -rf ./scpt/mkarchiso ./archiso/archiso/mkarchiso
$d/archiso/archiso/mkarchiso -v -o $d/ $d/archiso/configs/releng ./archiso/archiso/mkarchiso -v -o ./ ./archiso/configs/releng
if [ ! -d $d/root.x86_64 ];then if [ ! -d ./root.x86_64 ];then
tar xf $d/aios-bootstrap*.tar.gz tar xf ./aios-bootstrap*.tar.gz
fi fi
echo -e 'Server = http://mirrors.cat.net/archlinux/$repo/os/$arch\nServer = https://geo.mirror.pkgbuild.com/$repo/os/$arch' >> ./root.x86_64/etc/pacman.d/mirrorlist echo -e 'Server = http://mirrors.cat.net/archlinux/$repo/os/$arch\nServer = https://geo.mirror.pkgbuild.com/$repo/os/$arch' >> ./root.x86_64/etc/pacman.d/mirrorlist
@ -48,12 +42,9 @@ arch-chroot root.x86_64 /bin/sh -c 'pacman-key --populate archlinux'
arch-chroot root.x86_64 /bin/sh -c 'pacman -Syu --noconfirm base base-devel linux vim git zsh rust openssh openssl jq' arch-chroot root.x86_64 /bin/sh -c 'pacman -Syu --noconfirm base base-devel linux vim git zsh rust openssh openssl jq'
arch-chroot root.x86_64 /bin/sh -c 'git clone https://git.syui.ai/ai/bot && cd bot && cargo build && cp -rf ./target/debug/ai /bin/ && ai ai' arch-chroot root.x86_64 /bin/sh -c 'git clone https://git.syui.ai/ai/bot && cd bot && cargo build && cp -rf ./target/debug/ai /bin/ && ai ai'
# docker image
systemctl start docker systemctl start docker
tar -C $d/root.x86_64 -c . | docker import - syui/aios tar -C ./root.x86_64 -c . | docker import - syui/aios
docker images -a docker images -a
docker run --rm syui/aios ai docker run --rm syui/aios ai
docker push syui/aios docker push syui/aios
# docker run -it syui/aios zsh