diff --git a/README.md b/README.md index 8b71a7b..3e508f1 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,13 @@ on: jobs: dokploy_deploy: - uses: jmischler72/dokploy-deploy-actions@main + uses: tawandachiteshe/dokploy-deploy-actions@main with: - PROJECT_NAME: project-name - APPLICATION_NAME: application-name - DOKPLOY_HOST: ${{ secrets.DOKPLOY_HOST }} - DOKPLOY_TOKEN: ${{ secrets.DOKPLOY_TOKEN }} + PROJECT_NAME: "Project Name" + APPLICATION_NAME: "Application Name" + DOKPLOY_URL: ${{ secrets.DOKPLOY_URL }} + DOKPLOY_API_KEY: ${{ secrets.DOKPLOY_API_KEY }} + ENVIROMENT_NAME: production ``` @@ -36,4 +37,5 @@ jobs: - `PROJECT_NAME`: The name of the project in which the application you want to deploy is in - `APPLICATION_NAME`: The name of the application you want to deploy - `DOKPLOY_HOST`: The host ip or domain of your dokploy instance. -- `DOKPLOY_TOKEN`: Create an API token in your profile settings on Dokploy \ No newline at end of file +- `DOKPLOY_TOKEN`: Create an API token in your profile settings on Dokploy +- `ENVIROMENT_NAME`: The name of the environment you want to deploy to diff --git a/action.yaml b/action.yaml index ce0e596..d956b41 100644 --- a/action.yaml +++ b/action.yaml @@ -1,41 +1,67 @@ -name: "Dokploy Deploy Action" +name: "Tawanda Chiteshe Dokploy Deploy Action" description: "Deploy an application to Dokploy" -author: "jmischler72" +author: "tawandachiteshe" inputs: - APPLICATION_NAME: - description: "The name of the application to deploy" - required: true - default: "application" - PROJECT_NAME: - description: "The name of the project to deploy" - required: true - default: "project" - DOKPLOY_HOST: - description: "The host of the Dokploy instance" - required: true - DOKPLOY_TOKEN: - description: "The token to authenticate with Dokploy" - required: true - -runs: - using: "composite" - steps: - - name: Retrieve application id - id: retrieve-application-id - run: | - PROJECT_LIST=$(curl -X 'GET' 'https://${{ secrets.DOKPLOY_HOST }}/api/project.all' -H 'accept: application/json' -H 'Authorization: Bearer ${{ secrets.DOKPLOY_TOKEN }}') - echo "::add-mask::$PROJECT_LIST" - echo "APPLICATION_ID=$(echo $PROJECT_LIST | jq -r '.[] | select(.name == "${{ inputs.PROJECT_NAME }}") | .applications[] | select(.name == "${{ inputs.APPLICATION_NAME }}") | .applicationId')" >> "$GITHUB_OUTPUT" + DOKPLOY_URL: + description: "The URL of the Dokploy instance" + required: true + default: "dokploy.com" + DOKPLOY_API_KEY: + description: "The API key to authenticate with Dokploy" + required: true + APPLICATION_NAME: + description: "The name of the application to deploy" + required: true + default: "application" + PROJECT_NAME: + description: "The name of the project to deploy" + required: true + default: "project" + ENVIROMENT_NAME: + description: "The name of the project to deploy" + required: true + default: "production" + DOKPLOY_HOST: + description: "The host of the Dokploy instance" + required: true + DOKPLOY_TOKEN: + description: "The token to authenticate with Dokploy" + required: true - - name: Deploy to Dokploy - run: | - curl -X 'POST' \ - 'https://${{ secrets.DOKPLOY_HOST }}/api/application.deploy' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -H "Authorization: Bearer ${{ secrets.DOKPLOY_TOKEN }}" \ - -d '{ "applicationId": "${{ steps.retrieve-application-id.outputs.APPLICATION_ID }}" }' +runs: + using: "composite" + steps: + - name: Install JQ + shell: bash + run: | + if ! command -v jq &>/dev/null; then + sudo apt-get -qq update + sudo apt-get -qq install -y jq + fi + - name: Retrieve Application ID + shell: bash + id: retrieve-application-id + run: | + PROJECT_LIST=$(curl -X 'GET' 'https://${{ inputs.DOKPLOY_URL }}/api/project.all' -H 'accept: application/json' -H 'x-api-key: ${{ inputs.DOKPLOY_API_KEY }}') + echo "::add-mask::$PROJECT_LIST" + echo "APPLICATION_ID=$(echo $PROJECT_LIST | jq -r '.[] | select(.name == "${{ inputs.PROJECT_NAME }}") | .environments[] | select(.name == "${{ inputs.ENVIROMENT_NAME }}") | .applications[] | select(.name == "${{ inputs.APPLICATION_NAME }}") | .applicationId')" >> "$GITHUB_OUTPUT" + - name: Get Last Commit Message + id: last-commit-message + shell: bash + run: | + LAST_COMMIT_MESSAGE="$(git log -1 --pretty=format:%s)" + echo "LAST_COMMIT_MESSAGE=${LAST_COMMIT_MESSAGE}" >> "$GITHUB_OUTPUT" + - name: Deploy to Dokploy + shell: bash + run: | + curl -X 'POST' \ + 'https://${{inputs.DOKPLOY_URL}}/api/application.deploy' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -H "x-api-key: ${{ inputs.DOKPLOY_API_KEY }}" \ + -d '{ "applicationId": "${{ steps.retrieve-application-id.outputs.APPLICATION_ID }}", "title": "${{ steps.last-commit-message.outputs.LAST_COMMIT_MESSAGE }}", "description": "${{ github.sha }}" }' branding: icon: "box" - color: "gray-dark" \ No newline at end of file + color: "gray-dark" +