generated from Roxedus/Discord.py-BotBase
-
Notifications
You must be signed in to change notification settings - Fork 7
119 lines (104 loc) · 3.98 KB
/
build.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
name: Test And Build BOT
on:
push:
paths-ignore:
- ".github/**"
- ".devcontainer/**"
branches-ignore:
- "renovate/**"
pull_request:
branches-ignore:
- "renovate/**"
jobs:
tests:
runs-on: ubuntu-latest
env:
CheckFiles: "launcher.py cogs/"
steps:
- uses: actions/[email protected]
with:
ref: ${{ github.head_ref }}
- name: Set up Python 3.12
uses: actions/[email protected]
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
flake8 --select=E9,F63,F7,F82 --show-source
- name: Check with Isort
run: |
pip install isort
isort --check --sp setup.cfg $CheckFiles
- name: Sort with Isort
if: failure()
run: |
isort --sp setup.cfg $CheckFiles
- name: Create Pull Request
if: failure()
uses: peter-evans/[email protected]
with:
branch: actions/auto
commit-message: Changes done by tests
title: Linter changed files
build-and-push-container:
if: github.event_name != 'pull_request' && contains(github.ref, 'actions') != 'true'
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Create VARS
id: vars
run: |
echo "branch=${GITHUB_REF//refs\/heads\//}" >> $GITHUB_OUTPUT
echo "username=$(echo ${GITHUB_REPOSITORY} | cut -d/ -f1 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
echo "source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/${GITHUB_REF//refs\/heads\//}" >> $GITHUB_OUTPUT
echo "url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/blob/main/README.md" >> $GITHUB_OUTPUT
echo "tag=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]'):${GITHUB_SHA}" >> $GITHUB_OUTPUT
echo "bot_ver=$(cat cogs/utils/Bot_version.py | cut -d'"' -f 2)" >> $GITHUB_OUTPUT
# - name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ steps.vars.outputs.username }}
# password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ steps.vars.outputs.username }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
version: latest
driver-opts: image=moby/buildkit:master
- name: Build and push
uses: docker/[email protected]
with:
push: true
attests: type=sbom,generator=docker/buildkit-syft-scanner
provenance: true # https://github.com/docker/buildx/issues/1509
platforms: ${{ steps.vars.outputs.platform }}
file: ./amd64.Dockerfile
build-args: BUILDKIT_SBOM_SCAN_CONTEXT=true,BUILDKIT_SBOM_SCAN_STAGE=true
tags: |
ghcr.io/${{ steps.vars.outputs.tag }}
labels: |
org.opencontainers.image.source=${{ steps.vars.outputs.source }}
org.opencontainers.image.url=${{ steps.vars.outputs.url }}
- name: Create manifests for GitHub Container Registry
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
IMAGE=ghcr.io/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')
SOURCE=${IMAGE}:${GITHUB_SHA}
docker buildx imagetools create -t ${IMAGE}:${{ steps.vars.outputs.branch }} ${SOURCE}
if [[ ${GITHUB_REF//refs\/heads\//} == main ]]; then
docker buildx imagetools create -t ${IMAGE}:${{ steps.vars.outputs.bot_ver }} ${SOURCE}
docker buildx imagetools create -t ${IMAGE}:latest ${SOURCE}
fi