70 lines
2.4 KiB
YAML
70 lines
2.4 KiB
YAML
name: Publish Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [gitea]
|
|
|
|
env:
|
|
REGISTRY: gitea.nasvincent.com
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install dependencies
|
|
run: |
|
|
python3 -m pip install --upgrade pip
|
|
pip install -r src/requirements.txt
|
|
- name: Lint and format with Ruff
|
|
run: |
|
|
pip install ruff
|
|
ruff check src
|
|
ruff format --check src
|
|
|
|
build-and-push:
|
|
needs: test
|
|
runs-on: ubuntu-22.04
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Lowercase repository name
|
|
run: echo "IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')/discord-bot" >> $GITHUB_ENV
|
|
- name: Calculate new version
|
|
id: version
|
|
run: |
|
|
NEW_MINOR=$((${{ vars.VERSION_MINOR }} + 1))
|
|
NEW_VERSION="v${{ vars.VERSION_MAJOR }}.${NEW_MINOR}"
|
|
echo "new_minor=$NEW_MINOR" >> "$GITHUB_OUTPUT"
|
|
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
|
- uses: docker/setup-buildx-action@v3
|
|
- uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.USERNAME }}
|
|
password: ${{ secrets.TOKEN }}
|
|
- uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.new_version }}
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache
|
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache,mode=max
|
|
- name: Create Git tag
|
|
run: |
|
|
git config user.email "action@gitea.nasvincent.com"
|
|
git config user.name "Gitea Action"
|
|
git tag ${{ steps.version.outputs.new_version }}
|
|
git push origin ${{ steps.version.outputs.new_version }}
|
|
- name: Save new minor version
|
|
run: |
|
|
curl -s -X PUT "https://gitea.nasvincent.com/api/v1/repos/${{ github.repository }}/actions/variables/VERSION_MINOR" \
|
|
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"value\": \"${{ steps.version.outputs.new_minor }}\"}"
|