You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2022/04/01 07:14:29 UTC

[pulsar-test-infra] branch master updated: Update changes for gh-actions-artifact-client

This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-test-infra.git


The following commit(s) were added to refs/heads/master by this push:
     new d35becc  Update changes for gh-actions-artifact-client
d35becc is described below

commit d35becc40535f356b10bfc9c7bd648dc15247440
Author: Lari Hotari <la...@hotari.net>
AuthorDate: Fri Apr 1 10:12:34 2022 +0300

    Update changes for gh-actions-artifact-client
    
    - replace docker container action with js action
---
 gh-actions-artifact-client/.gitattributes     |  4 +--
 gh-actions-artifact-client/dist/Dockerfile    |  5 ----
 gh-actions-artifact-client/dist/action.yml    |  8 ++++++
 gh-actions-artifact-client/dist/entrypoint.sh | 12 ---------
 gh-actions-artifact-client/dist/install.js    | 36 +++++++++++++++++++++++++++
 gh-actions-artifact-client/test_install.sh    |  7 ++++++
 6 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/gh-actions-artifact-client/.gitattributes b/gh-actions-artifact-client/.gitattributes
index 7968c29..50920cf 100644
--- a/gh-actions-artifact-client/.gitattributes
+++ b/gh-actions-artifact-client/.gitattributes
@@ -1,2 +1,2 @@
-dist/*.js -diff linguist-generated=true
-dist/*.js.map -diff linguist-generated=true
+dist/index.js -diff linguist-generated=true
+dist/index.js.map -diff linguist-generated=true
diff --git a/gh-actions-artifact-client/dist/Dockerfile b/gh-actions-artifact-client/dist/Dockerfile
deleted file mode 100644
index 027705b..0000000
--- a/gh-actions-artifact-client/dist/Dockerfile
+++ /dev/null
@@ -1,5 +0,0 @@
-FROM alpine:latest
-RUN apk add --update bash && rm -rf /var/cache/apk/*
-COPY entrypoint.sh /entrypoint.sh
-COPY index.js /index.js
-ENTRYPOINT ["/entrypoint.sh"]
diff --git a/gh-actions-artifact-client/dist/action.yml b/gh-actions-artifact-client/dist/action.yml
new file mode 100644
index 0000000..1e2480c
--- /dev/null
+++ b/gh-actions-artifact-client/dist/action.yml
@@ -0,0 +1,8 @@
+name: 'GitHub Actions Artifact client'
+description: 'Install command line GitHub Actions Artifact client'
+author: 'Lari Hotari'
+branding:
+  icon: 'terminal'
+runs:
+  using: 'node16'
+  main: 'install.js'
diff --git a/gh-actions-artifact-client/dist/entrypoint.sh b/gh-actions-artifact-client/dist/entrypoint.sh
deleted file mode 100755
index 1887179..0000000
--- a/gh-actions-artifact-client/dist/entrypoint.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-printenv
-echo "Exporting ACTIONS_RUNTIME_TOKEN and ACTIONS_RUNTIME_URL to GITHUB_ENV"
-printf 'ACTIONS_RUNTIME_TOKEN<<EOF\n%s\nEOF\n' "${ACTIONS_RUNTIME_TOKEN}" >> $GITHUB_ENV
-printf 'ACTIONS_RUNTIME_URL<<EOF\n%s\nEOF\n' "${ACTIONS_RUNTIME_URL}" >> $GITHUB_ENV
-echo "Copy index.js to location in path as gh-actions-artifact-client.js"
-mkdir -p ~/.local/bin
-echo "#!/usr/bin/env node" > ~/.local/bin/gh-actions-artifact-client.js
-cat /index.js >> ~/.local/bin/gh-actions-artifact-client.js
-chmod a+rx ~/.local/bin/gh-actions-artifact-client.js
-echo "Add gh-actions-artifact-client.js to GITHUB_PATH"
-echo "${RUNNER_TEMP}/_github_home/.local/bin" >> $GITHUB_PATH
diff --git a/gh-actions-artifact-client/dist/install.js b/gh-actions-artifact-client/dist/install.js
new file mode 100644
index 0000000..e92ab55
--- /dev/null
+++ b/gh-actions-artifact-client/dist/install.js
@@ -0,0 +1,36 @@
+const fs = require('fs')
+const path = require('path')
+
+async function run() {
+  console.log(
+    'Exporting ACTIONS_RUNTIME_TOKEN and ACTIONS_RUNTIME_URL to GITHUB_ENV'
+  )
+  fs.appendFileSync(
+    process.env.GITHUB_ENV,
+    `ACTIONS_RUNTIME_TOKEN<<EOF\n${process.env.ACTIONS_RUNTIME_TOKEN}\nEOF\nACTIONS_RUNTIME_URL<<EOF\n${process.env.ACTIONS_RUNTIME_URL}\nEOF\n`
+  )
+  console.log(
+    'Copy index.js to location in path as gh-actions-artifact-client.js'
+  )
+  const localBinPath = path.resolve(
+    process.env.RUNNER_TEMP,
+    '_github_home/.local/bin'
+  )
+  fs.mkdirSync(localBinPath, {recursive: true})
+  const clientJsPath = path.resolve(
+    localBinPath,
+    'gh-actions-artifact-client.js'
+  )
+  const clientJsContent = fs.readFileSync(
+    path.resolve(__dirname, 'index.js'),
+    'UTF-8'
+  )
+  fs.writeFileSync(clientJsPath, `#!/usr/bin/env node\n${clientJsContent}`, {
+    encoding: 'UTF-8',
+    mode: '755'
+  })
+  console.log('Add gh-actions-artifact-client.js to GITHUB_PATH')
+  fs.appendFileSync(process.env.GITHUB_PATH, `${localBinPath}\n`)
+}
+
+run()
diff --git a/gh-actions-artifact-client/test_install.sh b/gh-actions-artifact-client/test_install.sh
new file mode 100755
index 0000000..11f6f6b
--- /dev/null
+++ b/gh-actions-artifact-client/test_install.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+export ACTIONS_RUNTIME_TOKEN=test_token
+export ACTIONS_RUNTIME_URL=http://localhost:12345/test_url
+export GITHUB_ENV=/tmp/github_env
+export GITHUB_PATH=/tmp/github_path
+export RUNNER_TEMP=/tmp/runner_temp
+node dist/install.js