Skip to content

Commit

Permalink
Refactor workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
mason committed Dec 18, 2024
1 parent 179bdfd commit 71810b5
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/release-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release CSGHub Docker Compose

on:
push:
tags:
- 'v\d+\.\d+\.\d+'

jobs:
assets:
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Package Custom Artifact
id: package_artifact
run: |
docker_artifact="csghub-docker-compose-${{ github.ref_name }}.tgz"
chart_artifact="csghub-helm-chart-${{ github.ref_name }}.tgz"
mv docker-compose csghub && tar -zcf $docker_artifact csghub
tar -zcf $chart_artifact helm-chart/charts/csghub
echo "artifacts=$docker_artifact,$chart_artifact" >> $GITHUB_OUTPUT
- name: Check if Release Exists
id: check_if_exists
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}")
if echo "$response" | grep -q "id"; then
upload_url=$(echo "$response" | jq -r '.upload_url')
echo "release_exists=true" >> $GITHUB_ENV
echo "upload_url=$upload_url" >> $GITHUB_OUTPUT
else
echo "release_exists=false" >> $GITHUB_ENV
fi
- name: Get Previous Tag
id: get_previous_tag
run: |
ALL_TAGS=$(git tag --sort=-v:refname)
CURRENT_TAG=${GITHUB_REF#refs/tags/}
PREVIOUS_TAG=$(echo "$ALL_TAGS" | grep -F -x -A 1 "$CURRENT_TAG" | tail -n 1)
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_ENV
- name: Generate Release Notes
id: generate_release_note
if: env.release_exists == 'false'
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/generate-notes" \
-d '{"tag_name":"${{ github.ref_name }}","target_commitish":"${{ github.sha }}","previous_tag_name":"${{ env.previous_tag }}"}')
if [[ $? -eq 0 ]] && [[ ! -z "$response" ]]; then
body=$(echo "$response" | jq -r '.body')
echo "$body" > release-notes.md
cat release-notes.md
fi
- name: Upload Release Assets
if: env.release_exists == 'true'
uses: softprops/action-gh-release@v2
with:
files: |
${{ steps.package_artifact.outputs.artifacts }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Release
uses: ncipollo/release-action@v1
if: env.release_exists == 'false'
with:
artifacts: ${{ steps.package_artifact.outputs.artifacts }}
bodyFile: "release-notes.md"
48 changes: 48 additions & 0 deletions .github/workflows/release-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release Docker Images

on:
push:
tags:
- 'v\d+\.\d+\.\d+'

jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login ACR
uses: docker/login-action@v3
with:
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
registry: ${{ secrets.ACR_REGISTRY }}

- name: Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.ACR_REGISTRY }}/opencsg_public/omnibus-csghub
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./docker
file: ./docker/Dockerfile
push: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
33 changes: 33 additions & 0 deletions .github/workflows/release-helm-chart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release CSGHub Helm Chart

on:
push:
tags:
- 'v\d+\.\d+\.\d+'

jobs:
package:
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4

- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: helm-chart/charts
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
File renamed without changes.

0 comments on commit 71810b5

Please sign in to comment.