mirror of https://github.com/h44z/wg-portal.git
105 lines
3.3 KiB
YAML
105 lines
3.3 KiB
YAML
name: Build, Push, and Release
|
|
|
|
on:
|
|
workflow_dispatch: {}
|
|
push:
|
|
branches: [master]
|
|
tags: ["v*.*.*"]
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
build-n-push:
|
|
name: Build and Push to GHCR
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.get_version.outputs.VERSION }}
|
|
|
|
steps:
|
|
- name: Check out the repo
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Get the version
|
|
id: get_version
|
|
run: |
|
|
if [[ "${{ github.ref_type }}" == "tag" ]]; then
|
|
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
|
|
else
|
|
LATEST_TAG=$(gh release list --repo ${{ github.repository }} --limit 1 --json tagName -q '.[0].tagName' || echo "v0.0.1")
|
|
echo "VERSION=${LATEST_TAG}" >> $GITHUB_OUTPUT
|
|
fi
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=semver,pattern={{version}},value=${{ steps.get_version.outputs.VERSION }}
|
|
type=semver,pattern={{major}}.{{minor}},value=${{ steps.get_version.outputs.VERSION }}
|
|
type=semver,pattern={{major}},value=${{ steps.get_version.outputs.VERSION }}
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
|
|
type=sha,format=short
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
build-args: |
|
|
BUILD_VERSION=${{ steps.get_version.outputs.VERSION }}
|
|
|
|
release:
|
|
name: Create GitHub Release
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
packages: read
|
|
needs: build-n-push
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
steps:
|
|
- name: Check out the repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract files from container
|
|
run: |
|
|
mkdir -p ./release-assets
|
|
IMAGE_TAG="${{ needs.build-n-push.outputs.version }}"
|
|
docker pull ghcr.io/${{ github.repository }}:$IMAGE_TAG
|
|
docker run --rm --entrypoint "" ghcr.io/${{ github.repository }}:$IMAGE_TAG \
|
|
tar -C /app -cf - . | tar -C ./release-assets -xf -
|
|
|
|
- name: Create GitHub Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
files: './release-assets/wg-portal_linux*'
|
|
generate_release_notes: true |