auto_release #20
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: auto_release | |
on: | |
schedule: | |
- cron: '0 1 * * *' | |
workflow_dispatch: | |
jobs: | |
release-and-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Download and rename latest release asset | |
id: download_latest_asset | |
run: | | |
gh release download --pattern "mosdns_config_*.tar.gz" --dir . | |
mv mosdns_config_*.tar.gz mosdns_config_latest.tar.gz | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Calculate sha256 of latest tarball | |
id: sha_latest_tarball | |
run: | | |
if [ -f mosdns_config_latest.tar.gz ]; then | |
echo "LATEST_TARBALL_HASH=$(sha256sum mosdns_config_latest.tar.gz | awk '{print $1}')" >> $GITHUB_ENV | |
else | |
echo "LATEST_TARBALL_HASH=" >> $GITHUB_ENV | |
fi | |
- name: Get the date | |
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV | |
- name: Archive etc directory | |
run: git archive -o "mosdns_config_${{ env.DATE }}.tar.gz" HEAD etc/ | |
- name: Calculate sha256 of new tarball | |
id: sha_new_tarball | |
run: echo "NEW_TARBALL_HASH=$(sha256sum mosdns_config_${{ env.DATE }}.tar.gz | awk '{print $1}')" >> $GITHUB_ENV | |
- name: Check if tarballs are different | |
run: | | |
if [ "$LATEST_TARBALL_HASH" != "$NEW_TARBALL_HASH" ]; then | |
echo "CHANGES_FOUND=true" >> $GITHUB_ENV | |
else | |
echo "CHANGES_FOUND=false" >> $GITHUB_ENV | |
fi | |
- name: Create Release and Upload Asset | |
if: env.CHANGES_FOUND == 'true' | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: v${{ env.DATE }} | |
name: v${{ env.DATE }} | |
body: "Package etc directory on date ${{ env.DATE }}" | |
files: mosdns_config_${{ env.DATE }}.tar.gz | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |