-
Notifications
You must be signed in to change notification settings - Fork 18
129 lines (108 loc) · 3.72 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Release
on:
push:
tags:
- "v*"
jobs:
github-release:
name: Publish GitHub release
runs-on: ubuntu-latest
permissions:
contents: write
env:
CHGLOG_VERSION: "0.15.4"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check SmartWatts package version
shell: python
env:
PYTHONPATH: ${{ github.workspace }}/src
run: |
import os
import sys
from smartwatts import __version__
git_tag = os.environ['GITHUB_REF_NAME'].removeprefix('v')
pkg_version = __version__
if git_tag != pkg_version:
title = 'Invalid version'
file = 'smartwatts/__init__.py'
msg = f'Version mismatch between python package ({pkg_version}) and git tag ({git_tag})'
print(f'::error title={title},file={file}::{msg}')
sys.exit(1)
- name: Generate version changelog
run: |
set -euo pipefail
export BASE_URL="https://github.com/git-chglog/git-chglog/releases/download"
export FILENAME="git-chglog_${CHGLOG_VERSION}_linux_amd64.tar.gz"
curl -fsSL "${BASE_URL}/v${CHGLOG_VERSION}/${FILENAME}" |sudo tar xz --no-same-owner -C /usr/local/bin git-chglog
git-chglog --config .github/chglog/config.yml --output CHANGELOG.md "${GITHUB_REF_NAME}"
- name: Create GitHub release
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974 # v2.1.0
with:
body_path: CHANGELOG.md
pypi-package:
name: Publish Pypi package
runs-on: ubuntu-latest
needs: github-release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@15c56dba361d8335944d31a2ecd17d700fc7bcbc # v1.12.2
with:
print-hash: true
docker-image:
name: Publish Docker image
runs-on: ubuntu-latest
needs: github-release
permissions:
contents: read
packages: write
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- name: Setup Docker buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Log in to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: |
docker.io/powerapi/smartwatts-formula
ghcr.io/powerapi-ng/smartwatts-formula
tags: |
type=pep440,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
id: build-and-push
with:
push: true
provenance: false
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}