From c8ff700f0cba77292fa2c2060474e60e72cbcba5 Mon Sep 17 00:00:00 2001 From: Adrien Carpentier Date: Thu, 16 May 2024 10:53:34 +0900 Subject: [PATCH] ci: fix GitHub actions CI --- .github/workflows/prod.yml | 21 ++++++++++----------- .github/workflows/staging.yml | 21 ++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 906a669..659f718 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -26,7 +26,7 @@ jobs: run: | jobs=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs) job_id=$(echo $jobs | jq -r '.jobs[] | select(.runner_name=="${{ runner.name }}") | .id') - echo "job_id=$job_id" >> $GITHUB_OUTPUT + echo "GITHUB_JOB_ID=$job_id" >> $GITHUB_ENV - name: Install SSH key uses: shimataro/ssh-key-action@v2 @@ -40,13 +40,12 @@ jobs: - name: Send deployment files to remote server run: | - mkdir -p ./${{ steps.get-job-id.outputs.job_id }} - cp -r ./app ./${{ steps.get-job-id.outputs.job_id }} - cp ./docker-compose.yml ./${{ steps.get-job-id.outputs.job_id }}/docker-compose.yml - cp ./Dockerfile ./${{ steps.get-job-id.outputs.job_id }}/Dockerfile - cp ./pyproject.toml ./${{ steps.get-job-id.outputs.job_id }}/pyproject.toml - cp ./.env ./${{ steps.get-job-id.outputs.job_id }}/.env - scp -i ${{ secrets.CI_DEPLOY_USER_SSH_PRIVATE_KEY }} -o StrictHostKeyChecking=no -r ./${{ steps.get-job-id.outputs.job_id }} ${{ secrets.CI_DEPLOY_USER }}@${{ secrets.CI_DEPLOY_HOST }}:/home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }} + mkdir -p ./${{ env.GITHUB_JOB_ID }} + cp -r ./app ./${{ env.GITHUB_JOB_ID }} + cp ./docker-compose.yml ./${{ env.GITHUB_JOB_ID }}/docker-compose.yml + cp ./Dockerfile ./${{ env.GITHUB_JOB_ID }}/Dockerfile + cp ./pyproject.toml ./${{ env.GITHUB_JOB_ID }}/pyproject.toml + scp -i ${{ secrets.CI_DEPLOY_USER_SSH_PRIVATE_KEY }} -o StrictHostKeyChecking=no -r ./${{ env.GITHUB_JOB_ID }} ${{ secrets.CI_DEPLOY_USER }}@${{ secrets.CI_DEPLOY_HOST }}:/home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }} - name: Execute server commands for deploy uses: appleboy/ssh-action@master @@ -55,10 +54,10 @@ jobs: username: ${{ secrets.CI_DEPLOY_USER }} key: ${{ secrets.CI_DEPLOY_USER_SSH_PRIVATE_KEY }} script: | - cd /home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }} + cd /home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }} mkdir -p /data/tchapbot - export COMPOSE_FILE=/home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }}/docker-compose.yml + export COMPOSE_FILE=/home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }}/docker-compose.yml export COMPOSE_PROJECT_NAME=albert-tchapbot docker compose down @@ -67,4 +66,4 @@ jobs: docker compose up --detach docker image rm albert/tchapbot:old || true - rm -rf /home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }} + rm -rf /home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }} diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 5643202..2898014 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -27,7 +27,7 @@ jobs: run: | jobs=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs) job_id=$(echo $jobs | jq -r '.jobs[] | select(.runner_name=="${{ runner.name }}") | .id') - echo "job_id=$job_id" >> $GITHUB_OUTPUT + echo "GITHUB_JOB_ID=$job_id" >> $GITHUB_ENV - name: Install SSH key uses: shimataro/ssh-key-action@v2 @@ -41,13 +41,12 @@ jobs: - name: Send deployment files to remote server run: | - mkdir -p ./${{ steps.get-job-id.outputs.job_id }} - cp -r ./app ./${{ steps.get-job-id.outputs.job_id }} - cp ./docker-compose.yml ./${{ steps.get-job-id.outputs.job_id }}/docker-compose.yml - cp ./Dockerfile ./${{ steps.get-job-id.outputs.job_id }}/Dockerfile - cp ./pyproject.toml ./${{ steps.get-job-id.outputs.job_id }}/pyproject.toml - cp ./.env ./${{ steps.get-job-id.outputs.job_id }}/.env - scp -i ${{ secrets.CI_DEPLOY_USER_SSH_PRIVATE_KEY }} -o StrictHostKeyChecking=no -r ./${{ steps.get-job-id.outputs.job_id }} ${{ secrets.CI_DEPLOY_USER }}@${{ secrets.CI_DEPLOY_HOST }}:/home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }} + mkdir -p ./${{ env.GITHUB_JOB_ID }} + cp -r ./app ./${{ env.GITHUB_JOB_ID }} + cp ./docker-compose.yml ./${{ env.GITHUB_JOB_ID }}/docker-compose.yml + cp ./Dockerfile ./${{ env.GITHUB_JOB_ID }}/Dockerfile + cp ./pyproject.toml ./${{ env.GITHUB_JOB_ID }}/pyproject.toml + scp -i ${{ secrets.CI_DEPLOY_USER_SSH_PRIVATE_KEY }} -o StrictHostKeyChecking=no -r ./${{ env.GITHUB_JOB_ID }} ${{ secrets.CI_DEPLOY_USER }}@${{ secrets.CI_DEPLOY_HOST }}:/home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }} - name: Execute server commands for deploy uses: appleboy/ssh-action@master @@ -56,10 +55,10 @@ jobs: username: ${{ secrets.CI_DEPLOY_USER }} key: ${{ secrets.CI_DEPLOY_USER_SSH_PRIVATE_KEY }} script: | - cd /home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }} + cd /home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }} mkdir -p /data/tchapbot - export COMPOSE_FILE=/home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }}/docker-compose.yml + export COMPOSE_FILE=/home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }}/docker-compose.yml export COMPOSE_PROJECT_NAME=albert-tchapbot docker compose down @@ -68,4 +67,4 @@ jobs: docker compose up --detach docker image rm albert/tchapbot:old || true - rm -rf /home/${{ secrets.CI_DEPLOY_USER }}/${{ steps.get-job-id.outputs.job_id }} + rm -rf /home/${{ secrets.CI_DEPLOY_USER }}/${{ env.GITHUB_JOB_ID }}