-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (74 loc) · 2.77 KB
/
Copy pathrelease.yml
File metadata and controls
86 lines (74 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Release
# the intention here is to always have a release (automated)
# but this workflow can be triggered from a workflow in nuonco/nuon
on:
workflow_dispatch:
schedule:
# Check daily at 06:00 UTC for a new API version
- cron: "0 6 * * *"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Get API version
id: version
run: |
API_VERSION=$(curl -sS https://api.nuon.co/version | jq -r '.version')
echo "api_version=$API_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$API_VERSION" >> "$GITHUB_OUTPUT"
echo "API version: $API_VERSION"
- name: Check if release already exists
id: check
run: |
TAG="${{ steps.version.outputs.tag }}"
if gh release view "$TAG" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Release $TAG already exists, skipping."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Release $TAG does not exist, proceeding."
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if tag already exists
id: tag
if: steps.check.outputs.exists == 'false'
run: |
TAG="${{ steps.version.outputs.tag }}"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag $TAG already exists."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Tag $TAG does not exist yet."
fi
- name: Download latest spec
if: steps.check.outputs.exists == 'false' && steps.tag.outputs.exists == 'false'
run: curl -sS https://api.nuon.co/docs/doc.json -o spec/doc.json
- name: Ensure tag exists for release
if: steps.check.outputs.exists == 'false' && steps.tag.outputs.exists == 'false'
run: |
TAG="${{ steps.version.outputs.tag }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add spec/doc.json
git diff --cached --quiet || git commit -m "spec: update to ${TAG}"
git tag -a "$TAG" -m "Release ${TAG}"
git push origin "refs/tags/$TAG"
- name: Run GoReleaser
if: steps.check.outputs.exists == 'false'
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.tag }}