Skip to content

Commit a02ad1d

Browse files
authored
feat: automatically update fpm formula on release (#41)
2 parents dbc3e34 + f0babed commit a02ad1d

File tree

5 files changed

+79
-10
lines changed

5 files changed

+79
-10
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Auto-update fpm Formula
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Runs daily at midnight UTC
6+
workflow_dispatch: # Allows manual trigger
7+
8+
jobs:
9+
update-fpm:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Fetch latest fpm release
17+
id: get-latest-release
18+
run: |
19+
VERSION_WITH_V="$(curl -s https://api.github.com/repos/fortran-lang/fpm/releases/latest | jq -r '.tag_name')"
20+
VERSION_WITHOUT_V="${VERSION_WITH_V#v}" # Remove leading 'v'
21+
echo "LATEST_VERSION=${VERSION_WITHOUT_V}" >> "$GITHUB_ENV"
22+
echo "LATEST_VERSION_V=${VERSION_WITH_V}" >> "$GITHUB_ENV"
23+
echo "Latest version: ${VERSION_WITH_V} (stripped: ${VERSION_WITHOUT_V})"
24+
25+
- name: Extract current formula version
26+
id: get-current-version
27+
run: |
28+
CURRENT_VERSION="$(grep -oP 'url "https://github.com/fortran-lang/fpm/releases/download/v\K[0-9.]+' Formula/fpm.rb)"
29+
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_ENV"
30+
echo "Current version: ${CURRENT_VERSION}"
31+
32+
- name: Compare versions
33+
id: check-update
34+
run: |
35+
if [ "${LATEST_VERSION}" != "${CURRENT_VERSION}" ]; then
36+
echo "New version available!"
37+
echo "UPDATE_NEEDED=true" >> "$GITHUB_ENV"
38+
else
39+
echo "No update needed."
40+
fi
41+
42+
- name: Get new SHA256 hash
43+
if: env.UPDATE_NEEDED == 'true'
44+
id: get-sha256
45+
run: |
46+
SHA_URL="https://github.com/fortran-lang/fpm/releases/download/${LATEST_VERSION_V}/fpm-${LATEST_VERSION}.zip.sha256"
47+
SHA256="$(curl -sL "${SHA_URL}" | awk '{print $1}')"
48+
echo "SHA256=${SHA256}" >> "$GITHUB_ENV"
49+
echo "New SHA256: ${SHA256}"
50+
51+
- name: Update formula
52+
if: env.UPDATE_NEEDED == 'true'
53+
run: |
54+
sed -i "s|url \".*\"|url \"https://github.com/fortran-lang/fpm/releases/download/${LATEST_VERSION_V}/fpm-${LATEST_VERSION}.zip\"|" Formula/fpm.rb
55+
sed -i "s|sha256 \".*\"|sha256 \"${SHA256}\"|" Formula/fpm.rb
56+
57+
- name: Commit and push changes
58+
if: env.UPDATE_NEEDED == 'true'
59+
run: |
60+
git config --global user.name "GitHub Actions"
61+
git config --global user.email "[email protected]"
62+
git add Formula/fpm.rb
63+
git commit -m "Update fpm to ${LATEST_VERSION}"
64+
git push
65+

.github/workflows/publish.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ on:
33
pull_request_target:
44
types:
55
- labeled
6+
67
jobs:
78
pr-pull:
89
if: contains(github.event.pull_request.labels.*.name, 'pr-pull')
910
runs-on: ubuntu-latest
11+
1012
steps:
1113
- name: Set up Homebrew
1214
uses: Homebrew/actions/setup-homebrew@master
@@ -19,16 +21,17 @@ jobs:
1921
HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }}
2022
HOMEBREW_NO_INSTALL_FROM_API: 1
2123
PULL_REQUEST: ${{ github.event.pull_request.number }}
22-
run: brew pr-pull --debug --tap=$GITHUB_REPOSITORY $PULL_REQUEST
24+
run: brew pr-pull --debug --tap="${GITHUB_REPOSITORY}" "${PULL_REQUEST}"
2325

2426
- name: Push commits
2527
uses: Homebrew/actions/git-try-push@master
2628
with:
2729
token: ${{ github.token }}
28-
branch: main
30+
branch: "main"
2931

3032
- name: Delete branch
3133
if: github.event.pull_request.head.repo.fork == false
3234
env:
3335
BRANCH: ${{ github.event.pull_request.head.ref }}
34-
run: git push --delete origin $BRANCH
36+
run: git push --delete origin "${BRANCH}"
37+

.github/workflows/tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
os: [macos-12, macos-13]
12+
os: [macos-13]
1313
runs-on: ${{ matrix.os }}
1414
timeout-minutes: 30
1515
steps:
@@ -19,11 +19,12 @@ jobs:
1919

2020
- name: Cache Homebrew Bundler RubyGems
2121
id: cache
22-
uses: actions/cache@v1
22+
uses: actions/cache@v4
2323
with:
2424
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
2525
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
26-
restore-keys: ${{ runner.os }}-rubygems-
26+
restore-keys: |
27+
${{ runner.os }}-rubygems-
2728
2829
- name: Install Homebrew Bundler RubyGems
2930
if: steps.cache.outputs.cache-hit != 'true'
@@ -40,7 +41,7 @@ jobs:
4041

4142
- name: Upload bottles as artifact
4243
if: always() && github.event_name == 'pull_request'
43-
uses: actions/upload-artifact@main
44+
uses: actions/upload-artifact@v4
4445
with:
4546
name: bottles
4647
path: '*.bottle.*'

Formula/lfortran.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Lfortran < Formula
1212

1313
depends_on "cmake" => :build
1414
depends_on "ninja" => :build
15-
depends_on "llvm@11"
15+
depends_on "llvm@14"
1616
depends_on "zlib"
1717

1818
def install
@@ -33,7 +33,7 @@ def install
3333
end
3434
EOS
3535
system "#{bin}/lfortran", testpath/"hello.f90", "-o", testpath/"hello"
36-
assert_predicate testpath/"hello", :exist?
36+
assert_path_exists testpath/"hello"
3737
system testpath/"hello"
3838
end
3939
end

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This repository provides package build instructions for tools and libraries arou
55
For example you can install *fpm* by tapping this repository
66

77
```
8-
brew tap fortran-lang/homebrew-fortran
8+
`brew tap fortran-lang/homebrew-fortran`
99
brew install fpm
1010
```
1111

0 commit comments

Comments
 (0)