-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (105 loc) · 3.87 KB
/
release.yml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
# Update versions and create release PR
# Source: https://www.thisdot.co/blog/tag-and-release-your-project-with-github-actions-workflows
# https://goreleaser.com/ci/actions/#tag-fetching
#
# - Manually triggered "release-prepare.yml" workflow will create a PR
# - This PR will do some minor tweaks to ready for release (such as increment the version across files)
# - Upon merging the PR, "release" job defined here will trigger, which will:
# - create a tag
# - do the actual release with goreleaser
name: release
on:
pull_request:
types:
- closed
permissions:
contents: read
jobs:
release-golang:
runs-on: ubuntu-latest
permissions:
contents: write # To create a new release
if: startsWith(github.event.pull_request.title, 'Release:') && github.event.pull_request.merged == true
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Set up Git
run: |
git config user.name "Release bot"
git config user.email "[email protected]"
- name: Get current version
id: get_version
run: |
git branch --show-current
git pull
echo "version=$(grep 'const firmwareActionVersion' < action/main.go | sed -E 's/.*= "//g' | sed 's/"//g')" >> "${GITHUB_OUTPUT}"
# Can't really use cocogitto here
- name: Create tag
run: |
NEXT_VERSION=${{ steps.get_version.outputs.version }}
git pull
git tag -a "${NEXT_VERSION}" -m "${NEXT_VERSION}"
git push --follow-tags
git checkout "${NEXT_VERSION}"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
workdir: action
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release-docker:
# There is a depth limit on workflows triggered by workflows to avoid infinite loops.
# This release workflow is triggered by merging a Pull Request made by release-prepare workflow.
#
# In addition the Docker build cannot really happen because of the `paths` filter in `on.push` event config.
# I do not want to change that because then we would build Docker containers all the time, which is long and unnecessary.
#
# And unfortunately a workflow cannot easily trigger another (Docker container builds) because of other GitHub limits.
# However it is possible to use API to trigger a workflow. That is what this job is for.
#
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
packages: write
needs: ['release-golang']
if: startsWith(github.event.pull_request.title, 'Release:') && github.event.pull_request.merged == true
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get tag of current commit
id: get_version
run: |
echo "version=$(git tag --points-at HEAD)" >> "${GITHUB_OUTPUT}"
- name: Trigger dagger workflow
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const result = await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'docker-build-and-test.yml',
ref: "${{ steps.get_version.outputs.version }}",
})
console.log(result);
} catch(error) {
console.error(error);
core.setFailed(error);
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}