ci - debug disk #140
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
push: | |
branches: | |
- main | |
release: | |
types: | |
- created | |
permissions: | |
contents: write | |
env: | |
NAME: lumni | |
jobs: | |
prebuild: | |
runs-on: ubuntu-latest | |
outputs: | |
release_tag: ${{ steps.generate_timestamp.outputs.release_tag }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Generate timestamp | |
id: generate_timestamp | |
run: | | |
TAG=$(bash ./ci/base36timestamp.sh) | |
echo "release_tag=$TAG" >> $GITHUB_OUTPUT | |
build: | |
needs: prebuild | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
#- target: aarch64-unknown-linux-gnu | |
# os: ubuntu-latest | |
#- target: x86_64-unknown-linux-musl | |
# os: ubuntu-latest | |
#- target: aarch64-unknown-linux-musl | |
# os: ubuntu-latest | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
env: | |
TARGET: ${{ matrix.target }} | |
OS: ${{ matrix.os }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Check disk usage | |
run: df -h | |
- name: Install and configure dependencies | |
run: | | |
# dependencies are only needed on ubuntu as that's the only place where | |
# we make cross-compilation | |
if [[ $OS =~ ^ubuntu.*$ ]]; then | |
sudo apt-get install -qq crossbuild-essential-arm64 | |
fi | |
# some additional configuration for cross-compilation on linux | |
cat >>~/.cargo/config <<EOF | |
[target.aarch64-unknown-linux-gnu] | |
linker = "aarch64-linux-gnu-gcc" | |
[target.aarch64-unknown-linux-musl] | |
linker = "aarch64-linux-gnu-gcc" | |
EOF | |
- name: Check disk usage | |
run: df -h | |
- name: Install target | |
run: rustup target add $TARGET | |
- name: Check disk usage | |
run: df -h | |
- name: Update version in Cargo.toml | |
id: update_version | |
run: | | |
CURRENT_VERSION=$(grep '^version' ./$NAME/Cargo.toml | sed 's/^version = \"\(.*\)\"/\1/') | |
if [[ $GITHUB_REF_TYPE == "tag" ]]; then | |
if [[ $GITHUB_REF_NAME =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}" | |
TAG=$GITHUB_REF_NAME | |
fi | |
else | |
TAG=${{ needs.prebuild.outputs.release_tag }} | |
VERSION="${CURRENT_VERSION%-pre}-$TAG" | |
fi | |
CARGO_TOML=$NAME/Cargo.toml | |
if [[ $OS == "macos-latest" ]]; then | |
sed -i '' "s/^version = \"[^\"]*\"/version = \"$VERSION\"/" ./$CARGO_TOML | |
else | |
sed -i "s/^version = \"[^\"]*\"/version = \"$VERSION\"/" ./$CARGO_TOML | |
fi | |
echo "Updated Cargo.toml to version $VERSION" | |
- name: Build project | |
run: cargo build -p $NAME --release --target $TARGET | |
- name: Check disk usage | |
run: df -h | |
- name: List target directory | |
run: ls target/${{ matrix.target }}/release | |
- name: Compress | |
run: | | |
[ -e ./build ] && rm -rf ./build | |
[ -e ./artifacts ] && rm -rf ./artifacts | |
mkdir -p ./artifacts ./build/bin | |
TAG=${{ needs.prebuild.outputs.release_tag }} | |
mv ./target/$TARGET/release/$NAME ./build/bin/$NAME | |
OUTFILE=./artifacts/$NAME-$TARGET-$TAG.tar.gz | |
tar -czf $OUTFILE -C ./build . | |
shasum -a 256 $OUTFILE > $OUTFILE.sha256 | |
- name: Archive artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.NAME }}-artifact | |
path: | | |
./artifacts | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [prebuild, build] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.NAME }}-artifact | |
path: ./artifacts | |
- name: List artifacts | |
run: find ./artifacts | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
files: | | |
./artifacts/*.tar.gz* | |
tag_name: ${{ needs.prebuild.outputs.release_tag }} | |
name: ${{ needs.prebuild.outputs.release_tag }} | |
body: Automated release for ${{ github.sha }} | |
update-formula: | |
runs-on: ubuntu-latest | |
needs: [prebuild, deploy] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: Get release tag from previous step | |
id: vars | |
run: | | |
echo "RELEASE_TAG=${{ needs.prebuild.outputs.release_tag }}" >> $GITHUB_ENV | |
- name: Get release information | |
id: release | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const release = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: process.env.RELEASE_TAG | |
}); | |
core.setOutput('release_tag', release.data.tag_name); | |
core.setOutput('assets', release.data.assets.map(asset => asset.browser_download_url).join('\n')); | |
- name: Download assets | |
run: | | |
mkdir -p assets | |
cd assets | |
echo "${{ steps.release.outputs.assets }}" | while IFS= read -r url; do | |
if [[ "$url" == *.tar.gz.sha256 ]]; then | |
echo "Downloading $url" | |
curl -LO "$url" | |
fi | |
done | |
- name: Extract SHA256 checksums | |
id: checksums | |
run: | | |
cd assets | |
# The following are examples for different platforms, uncomment as needed | |
SHA256_MAC_INTEL=$(awk '{print $1}' "${NAME}-x86_64-apple-darwin-${RELEASE_TAG}.tar.gz.sha256") | |
SHA256_MAC_ARM=$(awk '{print $1}' "${NAME}-aarch64-apple-darwin-${RELEASE_TAG}.tar.gz.sha256") | |
SHA256_LINUX_INTEL=$(awk '{print $1}' "${NAME}-x86_64-unknown-linux-gnu-${RELEASE_TAG}.tar.gz.sha256") | |
echo "SHA256_MAC_INTEL=${SHA256_MAC_INTEL}" >> "$GITHUB_OUTPUT" | |
echo "SHA256_MAC_ARM=${SHA256_MAC_ARM}" >> "$GITHUB_OUTPUT" | |
echo "SHA256_LINUX_INTEL=${SHA256_LINUX_INTEL}" >> "$GITHUB_OUTPUT" | |
- name: Checkout repository using Git and SSH | |
uses: actions/checkout@v3 | |
with: | |
repository: serverlessnext/homebrew-lumni | |
ssh-key: ${{ secrets.DEPLOY_KEY_HOMEBREW_LUMNI }} | |
path: homebrew-lumni | |
- name: Create a new feature branch | |
run: | | |
cd homebrew-lumni | |
git checkout -b gh-update-formula-${RELEASE_TAG} | |
- name: Update formula | |
run: | | |
cd homebrew-lumni/Formula | |
cp ../templates/lumni.rb.template lumni.rb | |
SHA256_MAC_INTEL="${{ steps.checksums.outputs.SHA256_MAC_INTEL }}" | |
SHA256_MAC_ARM="${{ steps.checksums.outputs.SHA256_MAC_ARM }}" | |
SHA256_LINUX_INTEL="${{ steps.checksums.outputs.SHA256_LINUX_INTEL }}" | |
sed -i "s|{{ RELEASE_TAG }}|${RELEASE_TAG}|g" lumni.rb | |
sed -i "s|{{ SHA256_MAC_INTEL }}|${SHA256_MAC_INTEL}|g" lumni.rb | |
sed -i "s|{{ SHA256_MAC_ARM }}|${SHA256_MAC_ARM}|g" lumni.rb | |
sed -i "s|{{ SHA256_LINUX_INTEL }}|${SHA256_LINUX_INTEL}|g" lumni.rb | |
- name: Start SSH agent and deploy key | |
env: | |
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY_HOMEBREW_LUMNI }} | |
run: | | |
eval "$(ssh-agent -s)" | |
echo "$DEPLOY_KEY" | ssh-add - | |
mkdir -p ~/.ssh | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
- name: Commit and push changes using custom SSH key | |
run: | | |
cd homebrew-lumni | |
git config user.email "[email protected]" | |
git config user.name "GitHub Action" | |
git add . | |
git commit -m "Update formula to release ${RELEASE_TAG}" | |
git push --set-upstream origin HEAD | |