Skip to content

Commit

Permalink
feat: automate homebrew-tap
Browse files Browse the repository at this point in the history
  • Loading branch information
omidasadpour committed Jan 29, 2024
1 parent 7da2c1a commit f4a208d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Node CI Suite
on: push
on:
push:
workflow_call:
jobs:
test:
runs-on: macos-latest
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/npm-package-updater.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Update NPM Package

on:
workflow_dispatch:
repository_dispatch:
types:
- update-package

jobs:
update-package:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 14

- name: Git configuration
run: |
git config --global user.email "bot@sunodo"
git config --global user.name "GitHub Actions release workflow"
- name: Install dependencies
run: npm install

- name: Get latest package information
id: get-package
run: |
PACKAGE_NAME="@sunodo/cli"
PACKAGE_VERSION=$(npm show $PACKAGE_NAME version)
PACKAGE_URL=$(npm show $PACKAGE_NAME dist.tarball)
PACKAGE_SHA512=$(npm show $PACKAGE_NAME dist.integrity)
npm pack @sunodo/cli@$PACKAGE_VERSION
DOWNLOADED_SHA512=$(cat ./sunodo-cli-$PACKAGE_VERSION.tgz | openssl dgst -sha512 -binary | openssl base64 -A)
# Compare the calculated hash with the hash provided by npm show
if [ "$PACKAGE_SHA512" != "sha512-$DOWNLOADED_SHA512" ]; then
echo "SHA512 hash verification failed! Exiting..."
exit 1
fi
echo "SHA512 hash verification successful!"
PACKAGE_SHA256=$(sha256sum sunodo-cli-$PACKAGE_VERSION.tgz | awk '{print $1}')
if [ -z "$PACKAGE_VERSION" ] || [ -z "$PACKAGE_URL" ] || [ -z "$PACKAGE_SHA256" ]; then
echo "Failed to retrieve package information. Exiting..."
exit 1
fi
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "PACKAGE_URL=$PACKAGE_URL" >> $GITHUB_ENV
echo "PACKAGE_SHA256=$PACKAGE_SHA256" >> $GITHUB_ENV
- name: Update formula file
run: |
sed -i.bak -e "s|url \".*\"|url \"$PACKAGE_URL\"|" Formula/sunodo.rb
sed -i.bak -e "s|sha256 \".*\"|sha256 \"$PACKAGE_SHA256\"|" Formula/sunodo.rb
- name: Commit CHANGELOG.md and package.json changes and create tag
run: |
git add Formula/sunodo.rb
git commit -m "chore: update NPM package to version ${{ env.PACKAGE_VERSION }}"
# Push changes to origin
- name: Push changes to repository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin
suite:
name: suite
needs: update-package
uses: ./.github/workflows/ci.yml

0 comments on commit f4a208d

Please sign in to comment.