From 31b225f386d4e2e075875af9a03be323a7153098 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 18 Nov 2023 20:17:43 +0200 Subject: [PATCH] github action configuration --- action.yml | 27 +++++++++++++++++++++++++++ docker-compose.yml | 10 +++++----- src/app.php | 34 +++++++++++++++++----------------- 3 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..79d2920 --- /dev/null +++ b/action.yml @@ -0,0 +1,27 @@ +name: "Gitea updating package" +description: "Updating a package in the Gitea system using GitHub Actions" +inputs: + gitea_instance_base_url: + description: "gitea instance base url" + required: true + gitea_access_token: + description: "gitea access token" + required: true + gitea_owner: + description: "gitea owner" + required: true + gitea_repository: + description: "gitea repository" + required: true + gitea_package_registry: + description: "gitea package registry" + required: true +runs: + using: "docker" + image: "Dockerfile" + args: + - ${{ inputs.gitea_instance_base_url }} + - ${{ inputs.gitea_access_token }} + - ${{ inputs.gitea_owner }} + - ${{ inputs.gitea_repository }} + - ${{ inputs.gitea_package_registry }} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 41a7fe3..e072375 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,11 +6,11 @@ services: context: ./ dockerfile: Dockerfile environment: - GITEA_INSTANCE_BASE_URL: ${GITEA_INSTANCE_BASE_URL} - GITEA_ACCESS_TOKEN: ${GITEA_ACCESS_TOKEN} - GITEA_OWNER: ${GITEA_OWNER} - GITEA_REPOSITORY: ${GITEA_REPOSITORY} - GITEA_PACKAGE_REGISTRY: ${GITEA_PACKAGE_REGISTRY} + gitea_instance_base_url: ${GITEA_INSTANCE_BASE_URL} + gitea_access_token: ${GITEA_ACCESS_TOKEN} + gitea_owner: ${GITEA_OWNER} + gitea_repository: ${GITEA_REPOSITORY} + gitea_package_registry: ${GITEA_PACKAGE_REGISTRY} volumes: - ./src:/var/src networks: diff --git a/src/app.php b/src/app.php index 25c6b2e..416a1bf 100644 --- a/src/app.php +++ b/src/app.php @@ -33,10 +33,10 @@ function sendRequest ($method = 'GET', $endpoint = '', $data = []): array { } if (isset($data['user']) && !empty($data['user'])) { - \curl_setopt($curl, CURLOPT_USERPWD, $data['user'] . ':' . \getenv('GITEA_ACCESS_TOKEN')); + \curl_setopt($curl, CURLOPT_USERPWD, $data['user'] . ':' . \getenv('gitea_access_token')); } - \curl_setopt($curl, CURLOPT_URL, \getenv('GITEA_INSTANCE_BASE_URL') . $endpoint .'?access_token=' . \getenv('GITEA_ACCESS_TOKEN')); + \curl_setopt($curl, CURLOPT_URL, \getenv('gitea_instance_base_url') . $endpoint .'?access_token=' . \getenv('gitea_access_token')); \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); \curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); @@ -104,28 +104,28 @@ function showTerminalMessage (string $message = '', string $color = ''): void try { - if (empty(\getenv('GITEA_INSTANCE_BASE_URL'))) { - throw new \Exception('GITEA_INSTANCE_BASE_URL empty'); + if (empty(\getenv('gitea_instance_base_url'))) { + throw new \Exception('gitea_instance_base_url empty'); } - if (empty(\getenv('GITEA_ACCESS_TOKEN'))) { - throw new \Exception('GITEA_ACCESS_TOKEN empty'); + if (empty(\getenv('gitea_access_token'))) { + throw new \Exception('gitea_access_token empty'); } - if (empty(\getenv('GITEA_OWNER'))) { - throw new \Exception('GITEA_OWNER empty'); + if (empty(\getenv('gitea_owner'))) { + throw new \Exception('gitea_owner empty'); } - if (empty(\getenv('GITEA_REPOSITORY'))) { - throw new \Exception('GITEA_REPOSITORY empty'); + if (empty(\getenv('gitea_repository'))) { + throw new \Exception('gitea_repository empty'); } - if (empty(\getenv('GITEA_PACKAGE_REGISTRY'))) { - throw new \Exception('GITEA_PACKAGE_REGISTRY empty'); + if (empty(\getenv('gitea_package_registry'))) { + throw new \Exception('gitea_package_registry empty'); } - if (!\in_array(\getenv('GITEA_PACKAGE_REGISTRY'), ['composer'])) { - throw new \Exception('Package registry {' . \getenv('GITEA_PACKAGE_REGISTRY') . '} is not supported'); + if (!\in_array(\getenv('gitea_package_registry'), ['composer'])) { + throw new \Exception('Package registry {' . \getenv('gitea_package_registry') . '} is not supported'); } $response = sendRequest('GET', '/api/v1/user'); @@ -141,7 +141,7 @@ try { - $response = sendRequest('GET', '/api/v1/repos/' . \getenv('GITEA_OWNER') . '/' . \getenv('GITEA_REPOSITORY') . '/releases'); + $response = sendRequest('GET', '/api/v1/repos/' . \getenv('gitea_owner') . '/' . \getenv('gitea_repository') . '/releases'); $data = responseEncode($response); if ($response['http_code'] !== 200) { @@ -157,7 +157,7 @@ try { showTerminalMessage('Last release data: OK', GREEN); - $response = sendRequest('GET', '/api/v1/repos/' . \getenv('GITEA_OWNER') . '/' . \getenv('GITEA_REPOSITORY') . '/archive/' . $tag . '.zip'); + $response = sendRequest('GET', '/api/v1/repos/' . \getenv('gitea_owner') . '/' . \getenv('gitea_repository') . '/archive/' . $tag . '.zip'); $zipContent = $response['body']; if ($response['http_code'] !== 200) { @@ -173,7 +173,7 @@ try { - $response = sendRequest('PUT', '/api/packages/' . \getenv('GITEA_OWNER') . '/composer?version=' . $tag, [ + $response = sendRequest('PUT', '/api/packages/' . \getenv('gitea_owner') . '/composer?version=' . $tag, [ 'user' => $login, 'file' => __DIR__ . '/package.zip', ]);