Skip to content

Rust cache

Rust cache #557

Workflow file for this run

on:
workflow_dispatch:
push:
branches-ignore:
- main
pull_request:
types: [ closed ]
branches: [ main ]
name: gg.cmd
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Generate version
if: github.event.pull_request.merged == true
id: buildnumber
uses: einaregilsson/build-number@v3
with:
token: ${{ github.token }}
- name: Set version
id: version
run: |
if [ "${{github.event.pull_request.merged}}" == "true" ]; then
echo "version=${{ steps.buildnumber.outputs.build_number }}" >> $GITHUB_OUTPUT
else
echo "version=dev" >> $GITHUB_OUTPUT
fi
stage4-OS:
strategy:
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: buildjet-2vcpu-ubuntu-2204-arm
target: aarch64-unknown-linux-musl
runs-on: ${{ matrix.os }}
needs: version
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
stage42/target
key: cache1-OS-${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Prepare build
shell: bash
run: |
if [[ "${{ matrix.os }}" == *"ubuntu"* ]]
then
sudo apt-get -y update
sudo apt-get -y install musl-dev musl-tools
export CC=musl-gcc
fi
rustup update
rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
workspace: "stage42"
- name: Build
shell: bash
run: |
mkdir -p stage42
mv src/stage4/* stage42
rm -rf src
cd stage42
export VERSION=${{needs.version.outputs.version}}
cargo test
cargo build --release --target=${{ matrix.target }}
find . -type f -name stage4.exe -exec cp {} ../stage4 \;
find . -type f -name stage4 -exec cp {} ../stage4 \;
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: stage4_${{ matrix.target }}
path: stage4
hash:
needs: [ stage4-OS ]
runs-on: ubuntu-20.04
steps:
- name: Download stage4 hash
uses: actions/download-artifact@v2
- name: Rename to hash
shell: bash
run: |
mkdir hash
mkdir out
touch hashes
for dir in stage4_*
do
file=$dir/stage4
hash=$(sha512sum $file | awk '{ print $1 }')
cp $file out/$hash
echo $hash > hash/hash_$dir
echo $dir=$hash >> hashes
done
- name: Upload hash artifact
uses: actions/upload-artifact@v2
with:
name: hash
path: hash
- name: Upload hash artifact
uses: actions/upload-artifact@v2
with:
name: hashes
path: hashes
- uses: LanceMcCarthy/[email protected]
with:
connection_string: ${{ secrets.ConnectionString }}
container_name: $web
source_folder: out
stage3-OS:
needs: hash
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
stage4: x86_64-apple-darwin
# TODO: Version too new
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
stage4: x86_64-unknown-linux-musl
- os: ubuntu-20.04
target: x86_64-unknown-linux-musl
stage4: x86_64-unknown-linux-musl
- os: buildjet-2vcpu-ubuntu-2204-arm
target: aarch64-unknown-linux-musl
stage4: aarch64-unknown-linux-musl
- os: buildjet-2vcpu-ubuntu-2204-arm
target: aarch64-unknown-linux-gnu
stage4: aarch64-unknown-linux-musl
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Download stage4 hash
uses: actions/download-artifact@v2
with:
name: hash
path: hash
- name: Hash
# ENV -> CMAKE -> Code very hard. This very easy
shell: bash
run: |
hash=$(cat hash/hash_stage4_${{ matrix.stage4 }})
echo "now hash is $hash"
echo "const char *hash = \"$hash\";" > src/stage3/const.h
- name: Makus
shell: bash
run: |
set -x
cd src/stage3
if [[ "${{ matrix.target }}" == *"musl"* ]]
then
sudo apt-get -y update
sudo apt-get -y install musl-dev musl-tools
export CC=musl-gcc
fi
cmake -B build -DCMAKE_EXE_LINKER_FLAGS='-Os' -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
find . -type f \( -name stage3 -o -name stage3.exe \) -exec cp {} ../../stage3_${{ matrix.target }} \;
strip ../../stage3_${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: stage3_${{ matrix.target }}
path: stage3_${{ matrix.target }}
stage1:
needs: [ version, stage3-OS ]
runs-on: ubuntu-latest
steps:
- name: Source
uses: actions/[email protected]
- name: Download stage3 / stage4
uses: actions/download-artifact@v2
- name: gg.cmd
run: |
sudo apt-get install dos2unix
mv src/stage1 _stage1
mv src/stage2 _stage2
mv src/stage3 _stage3
VERSION=${{needs.version.outputs.version}}
rm -rf .cache/gg/gg-$VERSION
mkdir -p .cache/gg/gg-$VERSION
rm -rf src
for dir in stage3*; do
for file in "$dir"/*; do
cp "$file" .cache/gg/gg-$VERSION/
done
done
# Prevent wine from trying to run (if installed on users PC)
# mv .cache/gg/stage3_x86_64-pc-windows-msvc .cache/gg/stage3_zz_x86_64-pc-windows-msvc
sed -i "s/VERVER/$VERSION/g" _stage2/stage2.*
cp _stage2/stage2.sh .cache/gg/gg-$VERSION/
cp _stage2/stage2.ps1 .cache/gg/gg-$VERSION/
cp hashes/hashes .cache/gg/gg-$VERSION/
chmod +x .cache/gg/gg-$VERSION/stage2.sh
tar -zpvcf gg.tgz .cache
sed -i "s/VERVER/$VERSION/g" _stage1/stage1.*
unix2dos _stage1/stage1.bat
cat _stage1/stage1.bat _stage1/stage1.sh > 1
a=$(du -cb 1 | tail -n 1 | awk '{print $1}')
b=a
((b++))
sed -i "s/AAA/$a/" 1;
sed -i "s/BBB/$b/" 1;
cat 1 gg.tgz > gg.cmd
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: gg.cmd
path: gg.cmd
- uses: LanceMcCarthy/[email protected]
with:
connection_string: ${{ secrets.ConnectionString }}
container_name: $web
source: gg.cmd
test-OS:
needs: stage1
strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022, macOS-11, macOS-12 ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version", "rat -V", "run:java@14 java -version", "deno -V" ]
runs-on: ${{ matrix.os }}
steps:
- name: Download gg
uses: actions/download-artifact@v2
with:
name: gg.cmd
- name: Run!
shell: bash
run: |
set -x
sh gg.cmd -v ${{ matrix.cmd }}
echo "Nice, let's try again"
sh gg.cmd -v ${{ matrix.cmd }}
test-ARM:
needs: stage1
strategy:
matrix:
os: [ buildjet-2vcpu-ubuntu-2204-arm ]
cmd: [ "java -version" ]
runs-on: ${{ matrix.os }}
steps:
- name: Download gg
uses: actions/download-artifact@v2
with:
name: gg.cmd
- name: Run!
shell: bash
run: |
set -x
sh gg.cmd -v ${{ matrix.cmd }}
echo "Nice, let's try again"
sh gg.cmd -v ${{ matrix.cmd }}
test-batch:
needs: stage1
strategy:
matrix:
os: [ windows-2019, windows-2022 ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version", "rat -V", "run:java@14 java -version", "deno -V" ]
runs-on: ${{ matrix.os }}
steps:
- name: Download gg
uses: actions/download-artifact@v2
with:
name: gg.cmd
- name: Run!
shell: cmd
run: |
.\gg.cmd -v ${{ matrix.cmd }}
echo "Nice, let's try again"
.\gg.cmd -v ${{ matrix.cmd }}
test-ARM-container:
needs: stage1
strategy:
matrix:
os: [ buildjet-2vcpu-ubuntu-2204-arm ]
container: [ alpine ]
cmd: [ "java -version" ]
runs-on: ${{ matrix.os }}
steps:
- name: Download gg
uses: actions/download-artifact@v3
with:
name: gg.cmd
- name: Run!
run: |
set -x
uname -a
docker run --rm -i -v $PWD:/b -w /b ${{ matrix.container }} sh gg.cmd -v ${{ matrix.cmd }}
test-container:
needs: stage1
strategy:
matrix:
container: [ ubuntu, debian, alpine, archlinux, 'ubuntu:14.04', 'ubuntu:18.04' ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version", "rat -V", "run:java@14 java -version" ]
runs-on: ubuntu-latest
container: ${{ matrix.container }}
steps:
- name: Download gg
uses: actions/download-artifact@v2
with:
name: gg.cmd
- name: Run!
run: |
set -x
# This is required for nodejs to run - not gg.cmd!
if [ "${{ matrix.container }}" == "alpine" ]; then
apk add libstdc++
fi
sh gg.cmd -v ${{ matrix.cmd }}
echo "Nice, let's try again"
sh gg.cmd -v ${{ matrix.cmd }}
release:
name: Release!
needs: [ version, test-OS, test-batch, test-container ]
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ needs.version.outputs.version }}
release_name: ${{ needs.version.outputs.version }}
body: ${{ github.event.pull_request.body }}
- name: Download gg
uses: actions/download-artifact@v2
with:
name: gg.cmd
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token}}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./gg.cmd
asset_name: gg.cmd
asset_content_type: text/x-shellscript