.github/workflows/update-brew-package.yml #29
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
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
inputs: | |
message: | |
description: "anything you'd like recorded for this workflow run" | |
required: false | |
type: "string" | |
default: "user manually triggered workflow" | |
permissions: | |
contents: write | |
jobs: | |
update_tap: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Get local tag | |
id: localTag | |
run: | | |
echo "tag=`echo $(git describe --tags --abbrev=0)`" | |
echo "tag=`echo $(git describe --tags --abbrev=0)`" >> "$GITHUB_OUTPUT" | |
- name: Get upstream release | |
id: upstreamRelease | |
uses: pozetroninc/github-action-get-latest-release@master | |
with: | |
repository: small-hack/smol-k8s-lab | |
- name: Update Release Version | |
run: | | |
echo -e "\n--------------------------------------------" | |
echo "replacing latest version\n" | |
export no_v_local=`echo ${{ steps.localTag.outputs.tag }} | tr -d 'v'` | |
export no_v_remote=`echo ${{ steps.upstreamRelease.outputs.release }} | tr -d 'v'` | |
sed -i "s/$no_v_local/$no_v_remote/g" ./Formula/smol-k8s-lab.rb && cat ./Formula/smol-k8s-lab.rb | |
echo -e "\n--------------------------------------------" | |
echo -e "replacing the sha of old version with new version\n" | |
export old_sha=`echo -n $(grep sha ./Formula/smol-k8s-lab.rb | awk -F ' ' '{print $2}' | sed 's/"//g')` | |
curl -sfLO https://github.com/small-hack/smol-k8s-lab/archive/refs/tags/${{ steps.upstreamRelease.outputs.release }}.tar.gz | |
export sha=`echo -n $(shasum -a 256 ${{ steps.upstreamRelease.outputs.release }}.tar.gz | cut -d ' ' -f 1)` | |
echo -e "old sha: $old_sha \nnew sha: $sha" | |
sed -i "s/$old_sha/$sha/" ./Formula/smol-k8s-lab.rb | |
git diff --quiet ./Formula/smol-k8s-lab.rb || export file_changed="1" | |
echo "file_changed: $file_changed" | |
if [[ $file_changed -ne 0 ]]; then | |
echo -e "\n--------------------------------------------" | |
echo -e "tagging and pushing to main branch\n" | |
git tag ${{ steps.upstreamRelease.outputs.release }} | |
git config --global user.email "jessebot@linux.com" && git config --global user.name "jessebot" | |
git commit -m "Updating latest package from ${{ steps.localTag.outputs.tag }} to ${{ steps.upstreamRelease.outputs.release }}" ./Formula/smol-k8s-lab.rb | |
git push && git push --tags --force | |
fi |