From dc0f6c2a928aa7bb6d35cbbb601ffbb28b2b4c09 Mon Sep 17 00:00:00 2001 From: ltitanb Date: Tue, 3 Sep 2024 13:46:43 +0100 Subject: [PATCH 1/2] add release CI --- .github/workflows/docker-publish.yml | 67 ----------------------- .github/workflows/draft-release.yml | 80 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/docker-publish.yml create mode 100644 .github/workflows/draft-release.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index 63136a26..00000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Deploy Images to GHCR - -on: - workflow_run: - workflows: [ "CI fmt clippy and test" ] - types: - - completed - push: - branches: - - main # Trigger only on push to main branch - tags: # Trigger on new tags - - 'v*' - -jobs: - push-store-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: 'Checkout GitHub Action' - uses: actions/checkout@main - - - name: 'Set up Docker Buildx' - uses: docker/setup-buildx-action@v1 - - - name: 'Login to GitHub Container Registry' - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: 'Extract short hash' - id: vars - run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV # This sets the SHORT_SHA environment variable - - - name: 'Set Docker tag' - id: docker_tag - run: | - if [[ "${{ github.ref }}" == refs/tags/* ]]; then - TAG_NAME=${{ github.ref }} - TAG_NAME=${TAG_NAME##*/} - echo "DOCKER_TAG=${TAG_NAME}" >> $GITHUB_ENV - else - echo "DOCKER_TAG=${{ env.SHORT_SHA }}" >> $GITHUB_ENV - fi - - - name: Build and push pbs - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ghcr.io/commit-boost/commit-boost-client/pbs:${{ env.DOCKER_TAG }} - cache-from: type=gha - cache-to: type=gha,mode=max - file: docker/pbs.Dockerfile - - - name: Build and push signer - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ghcr.io/commit-boost/commit-boost-client/signer:${{ env.DOCKER_TAG }} - cache-from: type=gha - cache-to: type=gha,mode=max - file: docker/signer.Dockerfile \ No newline at end of file diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml new file mode 100644 index 00000000..11360a7e --- /dev/null +++ b/.github/workflows/draft-release.yml @@ -0,0 +1,80 @@ +name: Draft Release + +on: + push: + tags: + - "v*" + +env: + BINARY_NAME: commit-boost + +jobs: + create-draft-release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push PBS Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ghcr.io/${{ github.repository }}/pbs:${{ github.ref_name }} + ghcr.io/${{ github.repository }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + file: docker/pbs.Dockerfile + + - name: Build and push Signer Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ghcr.io/${{ github.repository }}/signer:${{ github.ref_name }} + ghcr.io/${{ github.repository }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + file: docker/pbs.Dockerfile + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Build Linux binary + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --target x86_64-unknown-linux-gnu --bin ${{ env.BINARY_NAME }} + + - name: Create Draft Release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + draft: true + prerelease: false + + - name: Upload Linux Binary + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }} + asset_name: ${{ env.BINARY_NAME }}-linux-amd64 + asset_content_type: application/octet-stream From 278a088faf08b9ea03c285f57428494ebb49fd80 Mon Sep 17 00:00:00 2001 From: ltitanb Date: Tue, 3 Sep 2024 14:11:52 +0100 Subject: [PATCH 2/2] fixex --- .github/workflows/draft-release.yml | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 11360a7e..f91fb325 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -8,6 +8,10 @@ on: env: BINARY_NAME: commit-boost +permissions: + contents: write + packages: write + jobs: create-draft-release: runs-on: ubuntu-latest @@ -16,23 +20,23 @@ jobs: uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push PBS Docker image - uses: docker/build-push-action@v6 + uses: ndocker/build-push-actio@v6 with: context: . push: true tags: | ghcr.io/${{ github.repository }}/pbs:${{ github.ref_name }} - ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}/pbs:latest cache-from: type=gha cache-to: type=gha,mode=max file: docker/pbs.Dockerfile @@ -44,7 +48,7 @@ jobs: push: true tags: | ghcr.io/${{ github.repository }}/signer:${{ github.ref_name }} - ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}/signer:latest cache-from: type=gha cache-to: type=gha,mode=max file: docker/pbs.Dockerfile @@ -62,19 +66,15 @@ jobs: command: build args: --release --target x86_64-unknown-linux-gnu --bin ${{ env.BINARY_NAME }} + - name: Rename binary + run: | + mv target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }} ${{ env.BINARY_NAME }}-linux-amd64 + - name: Create Draft Release - id: create_release - uses: actions/create-release@v1 + uses: softprops/action-gh-release@v2 with: + name: Release ${{ github.ref_name }} tag_name: ${{ github.ref_name }} - release_name: Release ${{ github.ref_name }} draft: true prerelease: false - - - name: Upload Linux Binary - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }} - asset_name: ${{ env.BINARY_NAME }}-linux-amd64 - asset_content_type: application/octet-stream + files: ${{ env.BINARY_NAME }}-linux-amd64