This commit is contained in:
Darwin Cereska
2025-06-19 17:12:49 -04:00
parent 9257e21df3
commit c8901fc3c9
2 changed files with 64 additions and 30 deletions

View File

@@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: gem install --no-document toml-rb
- name: Fetch latest release info
- name: Fetch latest release tarball URL
id: release
uses: actions/github-script@v6
with:
@@ -31,32 +31,49 @@ jobs:
const release = await github.rest.repos.getLatestRelease({
owner: 'darwincereska',
repo: 'xswitcher'
})
return release.data.tarball_url
});
return release.data.tarball_url;
- name: Calculate SHA256 of tarball
id: sha256
run: |
curl -L -o release.tar.gz ${{ steps.release.outputs.result }}
sha256sum release.tar.gz | awk '{ print $1 }' > sha256.txt
echo "::set-output name=hash::$(cat sha256.txt)"
curl -L -o release.tar.gz "${{ steps.release.outputs.result }}"
SHA256=$(sha256sum release.tar.gz | awk '{ print $1 }')
echo "hash=$SHA256" >> $GITHUB_OUTPUT
- name: Get release version
id: version
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const release = await github.rest.repos.getLatestRelease({
owner: 'darwincereska',
repo: 'xswitcher'
});
return release.data.tag_name;
- name: Update formula file
run: |
VERSION=${{ steps.release.outputs.data.tag_name }}
VERSION=${{ steps.version.outputs.result }}
SHA256=${{ steps.sha256.outputs.hash }}
FORMULA_FILE=Formula/xswitcher.rb
# Replace url and sha256 in the formula
echo "Updating formula to version $VERSION with sha256 $SHA256"
sed -i "s|url \".*\"|url \"https://github.com/darwincereska/xswitcher/archive/refs/tags/${VERSION}.tar.gz\"|g" $FORMULA_FILE
sed -i "s/sha256 \".*\"/sha256 \"${SHA256}\"/g" $FORMULA_FILE
sed -i "s/version \".*\"/version \"${VERSION#v}\"/g" $FORMULA_FILE || echo "No version line to update"
- name: Commit and push changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/xswitcher.rb
git commit -m "Bump xswitcher to $VERSION" || echo "No changes to commit"
git push origin HEAD:main
- name: Commit and push if changed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add Formula/xswitcher.rb
if ! git diff --cached --quiet; then
git commit -m "Auto-update to build ${{ steps.version.outputs.result }}"
git push
else
echo "No changes to commit"