Skip to content

Commit d69baa6

Browse files
authored
Use GitHub API to fetch latest release/version (#1870)
* Use GitHub API to fetch latest release/version * Make it easier to copy and paste into other repos * add some auth * used auth version everywhere
1 parent 031e13c commit d69baa6

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

.github/workflows/conda_cron.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
id: latest-version
4141
working-directory: openfe_repo
4242
run: |
43-
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
44-
# slice off the v, ie v0.7.2 -> 0.7.2
45-
VERSION=${LATEST_TAG:1}
43+
REPO="${{ github.repository }}"
44+
VERSION=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
45+
"https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name | ltrimstr("v")')
4646
echo $VERSION
4747
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
4848

.github/workflows/docker.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ jobs:
7878
- name: Get Latest Version
7979
id: latest-version
8080
run: |
81-
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
82-
echo $LATEST_TAG
83-
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
84-
# slice off the v, ie v0.7.2 -> 0.7.2
85-
VERSION=${LATEST_TAG:1}
81+
REPO="${{ github.repository }}"
82+
VERSION=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
83+
"https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name | ltrimstr("v")')
8684
echo $VERSION
8785
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
8886

.github/workflows/gen-lock-file.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@ jobs:
2222
# This saves me some time since we only need the latest tag
2323
- name: Get latest tag
2424
id: latest-version
25-
env:
26-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27-
REPO: ${{ github.repository }}
2825
run: |
29-
LATEST_TAG=$(curl -s -H "Authorization: token $GH_TOKEN" \
30-
https://api.github.com/repos/$REPO/tags \
31-
| jq -r '.[0].name')
32-
VERSION=${LATEST_TAG:1}
26+
REPO="${{ github.repository }}"
27+
VERSION=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
28+
"https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name | ltrimstr("v")')
3329
echo $VERSION
3430
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
3531

.github/workflows/installer.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
- name: Get Latest Version
2626
id: latest-version
2727
run: |
28-
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
29-
# slice off the v, ie v0.7.2 -> 0.7.2
30-
VERSION=${LATEST_TAG:1}
28+
REPO="${{ github.repository }}"
29+
VERSION=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
30+
"https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name | ltrimstr("v")')
3131
echo $VERSION
3232
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
3333

0 commit comments

Comments
 (0)