Skip to content

Instantly share code, notes, and snippets.

@seb86
Created October 30, 2024 17:50
Show Gist options
  • Save seb86/9da0eae0402a1ef84b8edd83e494116c to your computer and use it in GitHub Desktop.
Save seb86/9da0eae0402a1ef84b8edd83e494116c to your computer and use it in GitHub Desktop.
GitHub Action Workflow: Zip and Checksum Generated upon Release
name: Zip and Checksum on Release
on:
release:
types: [published]
jobs:
checksum:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set Up Node.js
uses: actions/setup-node@v2
with:
node-version: '16' # Change to your required Node.js version
- name: Install Dependencies
run: npm install
- name: Get Package Info
id: package_info
run: |
echo "PACKAGE_NAME=$(node -p "require('./package.json').name")" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
- name: Generate Checksum File
run: |
checksum_file="checksum.md5"
find . \
-type f \
-not -path '*/.*' \
-not -name '*.zip' \
-not -name '*.tar.gz' \
-not -name '*.md5' \
-not -name '*.dist' \
-not -name '*.gif' \
-not -name '*.html' \
-not -name '*.jpg' \
-not -name '*.jpeg' \
-not -name '*.js' \
-not -name '*.json' \
-not -name '*.log' \
-not -name '*.lock' \
-not -name '*.md' \
-not -name '*.png' \
-not -name '*.scss' \
-not -name '*.sh' \
-not -name '*.txt' \
-not -name '*.xml' \
-not -path '*/assets/scss/*' \
-not -path '*/bin/*' \
-not -path '*/node_modules/*' \
-not -path '*/releases/*' \
-not -path '*/tests/*' \
-not -path '*/vendor/*' \
-not -path '*/unit-tests/*' \
-exec md5sum {} + > $checksum_file
- name: Create ZIP Archive
run: |
zip -r "${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.zip" . \
-x '.*' \
'**/*.{dist,gif,html,jpg,jpeg,js,json,log,lock,md,png,scss,sh,txt,xml,zip}' \
'!/.*' \
'!assets/scss/**' \
'!assets/**/*.scss' \
'!bin/**' \
'!node_modules/**' \
'!releases/**' \
'!tests/**' \
'!vendor/**' \
'!unit-tests/**' \
checksum.md5
- name: Create TAR.GZ Archive
run: |
tar -czf "${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.tar.gz" \
--exclude='.*' \
--exclude='**/*.{dist,gif,html,jpg,jpeg,js,json,log,lock,md,png,scss,sh,txt,xml,zip}' \
--exclude='assets/scss/**' \
--exclude='assets/**/*.scss' \
--exclude='bin/**' \
--exclude='node_modules/**' \
--exclude='releases/**' \
--exclude='tests/**' \
--exclude='vendor/**' \
--exclude='unit-tests/**' \
. checksum.md5
upload:
needs: checksum
runs-on: ubuntu-latest
steps:
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
tag: ${{ github.event.release.tag_name }}
files: |
${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.zip
${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.tar.gz
checksum.md5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment