Skip to content

Update build.yml

Update build.yml #938

Workflow file for this run

name: Create zip files
on:
push:
branches:
- main
jobs:
create-zip-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create name version env
run: |
sudo timedatectl set-timezone Asia/Singapore
echo "DATE=$(date +%y.%m)" >> $GITHUB_ENV
echo "COUNT=$(git rev-list --count HEAD --since=$(date --date="$(date +%Y-%m-01) - 1 second" +%s) | xargs printf "%02d")" >> $GITHUB_ENV
echo "SHA_SHORT=$(echo ${{ github.sha }} | cut -c -7)" >> $GITHUB_ENV
echo "DATE_OLD=$(date +%Y-%m-%d)" >> $GITHUB_ENV
- name: Create git hash and version
run: |
echo "${{ env.SHA_SHORT }}" | tee ./resources/git_hash
echo "v${{ env.DATE }}.${{ env.COUNT }}" | tee ./resources/version
- name: Move binaries
run: |
mkdir -p ./exclude/bin ./exclude/resources
cp -R ./bin/* ./exclude/bin
cp -R ./resources/* ./exclude/resources
rm -rf ./bin/* ./resources/*
mkdir -p ./bin/macos/arm64 ./bin/linux/arm64 ./bin/linux/x86_64
mv ./exclude/bin/linux/arm64/jq ./bin/linux/arm64
mv ./exclude/bin/linux/x86_64/jq ./bin/linux/x86_64
mv ./exclude/bin/macos/jq ./bin/macos
mv ./exclude/bin/macos/arm64/jq ./bin/macos/arm64
touch ./resources/new
- name: Zip files
run: zip -r ${{ github.event.repository.name }}_v${{ env.DATE }}.${{ env.COUNT }}.zip bin/ LICENSE resources/ restore.sh README.md
- name: Create this file to get latest git hash
run: |
echo "This file is for version checking purposes only. Get the correct zip file for your platform in the release assets." > README.txt
zip -r git-hash_${{ env.DATE_OLD }}-${{ env.SHA_SHORT }}.zip README.txt
- name: Remove all assets from latest release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
assets=$(gh release view latest --json assets -q '.assets[].name' || true)
if [[ -z "$assets" ]]; then
echo "No assets found on release 'latest'"
exit 0
fi
for asset in $assets; do
echo "Deleting asset: $asset"
gh release delete-asset latest "$asset" -R ${{ github.repository }} -y
done
- name: Update latest release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload latest \
git-hash_${{ env.DATE_OLD }}-${{ env.SHA_SHORT }}.zip \
${{ github.event.repository.name }}_v${{ env.DATE }}.${{ env.COUNT }}.zip \
--clobber -R ${{ github.repository }}
gh release edit latest \
--title "Latest-v${{ env.DATE }}.${{ env.COUNT }}" \
--target ${{ github.sha }} -R ${{ github.repository }}