-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (128 loc) · 4.56 KB
/
deploy.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Build Docker image
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
on:
push:
branches: [ "main" ]
tags:
- "v*.*.*"
pull_request:
types: [ closed ]
branches:
- 'release/*.*.*'
workflow_dispatch:
permissions:
contents: write
packages: write
pull-requests: write
jobs:
lint:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
is_pr: ${{ steps.release.outputs.is_pr == 'true'}}
is_tag: ${{ steps.release.outputs.is_tag == 'true'}}
is_release: ${{ steps.release.outputs.is_release == 'true'}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Get version from pyproject.toml
id: get_version
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
- name: Is it a releasable?
id: release
run: |
is_pr="${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true }}"
is_tag="${{ startsWith(github.ref, 'refs/tags/') }}"
[[ "$is_pr" == "true" || "$is_tag" == "true" ]] && is_release=true || is_release=false
echo "is_pr=$is_pr" >> $GITHUB_OUTPUT
echo "is_tag=$is_tag" >> $GITHUB_OUTPUT
echo "is_release=$is_release" >> $GITHUB_OUTPUT
- name: Run Ruff
run: poetry run ruff check --output-format=github .
- name: Run pre-commit hooks
run: poetry run pre-commit run --all-files --show-diff-on-failure
build:
needs:
- lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha
type=semver,pattern={{version}},value=${{ needs.lint.outputs.version }},enabled=${{ needs.lint.outputs.is_release }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.lint.outputs.version }},enabled=${{ needs.lint.outputs.is_release }}
type=semver,pattern={{major}},value=${{ needs.lint.outputs.version }},enabled=${{ needs.lint.outputs.is_release }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7
release:
runs-on: ubuntu-latest
if: ${{ needs.lint.outputs.is_release }}
needs:
- build
steps:
- name: Create Tag
id: create_tag
uses: actions/github-script@v7
if: ${{ needs.lint.outputs.is_pr }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const version = "${{ needs.lint.outputs.version }}"
const tagMessage = `Release version ${version}`
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/v${version}`,
sha: context.sha
})
github.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${version}`,
name: `v${version}`,
body: tagMessage
})
- name: Release
uses: softprops/action-gh-release@v2
with:
body: |
Docker image: [`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.version }}`](https://github.com/jag-k/owntinfoil/pkgs/container/owntinfoil/${{ steps.docker_build.outputs }}?tag=${{ steps.get_version.outputs.version }})
tag_name: v${{ steps.get_version.outputs.version }}
generate_release_notes: true
append_body: true