From 13933b8a735be9589638a4fe68fead0bdb76edf8 Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Sat, 27 Apr 2024 20:08:26 +0300 Subject: [PATCH 1/5] Beautified example.yml --- bamboo-specs/example.yaml | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/bamboo-specs/example.yaml b/bamboo-specs/example.yaml index 73643f4..bd2aaba 100644 --- a/bamboo-specs/example.yaml +++ b/bamboo-specs/example.yaml @@ -1,3 +1,13 @@ +# This is an example Atlassian Bamboo CI configuration that demonstrates how to +# use github-actions-runner to run a GitHub Actions workflow in a Bamboo CI job. +# +# Check out .github/workflows/example.yml to see what workflow this Bamboo job +# actually runs. +# +# This example demonstrates how to: +# * Trigger a workflow run. +# * Download the artifacts produced by the workflow. +# * Pass secrets from the CI to the workflow. --- version: 2 plan: @@ -5,8 +15,10 @@ plan: key: GHACTIONSRUNEXAMPLE name: github-actions-runner - example variables: - # TODO replace to :latest-ci - dockerNode: ghcr.io/adguardteam/githubactionsrunner:latest-no-entrypoint + # Using github-actions-runner Docker image for the latest stable version. + # latest-ci docker image does not have any entrypoint and has the + # runner installed. + dockerNode: ghcr.io/adguardteam/githubactionsrunner:latest-ci stages: - Test: @@ -21,8 +33,6 @@ Test: clean-working-dir: true docker: image: ${bamboo.dockerNode} - volumes: - ${system.PNPM_DIR}: ${bamboo.cachePnpm} tasks: - checkout: force-clean-build: true @@ -30,23 +40,21 @@ Test: interpreter: SHELL scripts: - |- - set -x + # Make sure the script fails on any error. set -e - # Combine stderr and stdout for consistent log output + # Combine stderr and stdout for consistent log output. exec 2>&1 - ls -laht - - branch="${bamboo_planRepository_branchName}" - revision="${bamboo_planRepository_revision}" - GITHUB_TOKEN=${bamboo.githubActionsRunnerPassword} github-actions-runner run-action \ --repo AdguardTeam/GithubActionsRunner \ - --branch "$branch" \ - --rev "$revision" \ + --branch "${bamboo_planRepository_branchName}" \ + --rev "${bamboo_planRepository_revision}" \ --workflow example.yml \ - --artifacts-path . \ + --artifacts-path . + # The artifacts produced by the workflow are downloaded and shared with the + # Bamboo CI job. These artifacts can be then shared with other unrelated + # Bamboo builds. artifacts: - name: github-actions-runner.tgz pattern: github-actions-runner.tgz From 79edf6910ab6174dbba664e2ccfdd999b460d3e1 Mon Sep 17 00:00:00 2001 From: Maxim Topciu Date: Sat, 27 Apr 2024 20:27:41 +0300 Subject: [PATCH 2/5] remove lint, and test from example --- .github/workflows/example.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 60822d6..bc073e3 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -41,12 +41,6 @@ jobs: # Install deps pnpm install - # Linting package - pnpm lint - - # Testing package - pnpm test - # Building package artifact pnpm pack && mv adguard-github-actions-runner-*.tgz github-actions-runner.tgz From 85499bd64e47931f12233d1b8c22c0d1b411a612 Mon Sep 17 00:00:00 2001 From: Maxim Topciu Date: Sat, 27 Apr 2024 20:44:16 +0300 Subject: [PATCH 3/5] fix hasCommit method --- src/lib/github/GithubApiManager.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/lib/github/GithubApiManager.ts b/src/lib/github/GithubApiManager.ts index c7e2999..03d4dc3 100644 --- a/src/lib/github/GithubApiManager.ts +++ b/src/lib/github/GithubApiManager.ts @@ -76,18 +76,26 @@ export class GithubApiManager { } /** - * Checks if a commit exists. - * @param commitRef The reference for the commit to check (SHA). - * @returns A boolean indicating if the commit exists. - * @throws An error if the commit check fails. + * Checks if a commit exists for the specified commit reference. + * The function considers a commit to exist if the server returns a 200 OK status. + * It handles certain non-200 statuses explicitly without throwing: + * - 404 Not Found and 422 Unprocessable Entity are treated as the commit not existing. + * + * @param commitRef The SHA reference for the commit to check. + * @returns A boolean indicating if the commit exists (true) or not (false). + * @throws An error if the server response indicates an error (other than 404 or 422) + * or if there is an issue with network connectivity or request formation. */ private async hasCommit(commitRef: string): Promise { try { const response = await this.githubApiClient.getCommit(commitRef); return response.status === HttpStatusCode.Ok; } catch (error) { - if (isErrorWithStatus(error) && error.status === HttpStatusCode.NotFound) { - return false; + if (isErrorWithStatus(error)) { + if (error.status === HttpStatusCode.NotFound || error.status === HttpStatusCode.UnprocessableEntity) { + // Return false if the commit does not exist, or if the request is unprocessable + return false; + } } throw error; } From 1e4c1cb2e5fdd86041ccb4f0a38aa28f3055e4b4 Mon Sep 17 00:00:00 2001 From: Maxim Topciu Date: Sat, 27 Apr 2024 20:48:26 +0300 Subject: [PATCH 4/5] simplify example plans --- .github/workflows/example.yml | 26 +++----------------------- bamboo-specs/example.yaml | 9 +++++---- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index bc073e3..b034e07 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -1,9 +1,6 @@ # Example workflow for github-actions-runner name: Example -env: - NODE_VERSION: 20 - on: workflow_dispatch: inputs: @@ -24,35 +21,18 @@ jobs: with: # Number of commits to fetch. 0 indicates all history. fetch-depth: 0 - - name: Setup pnpm - uses: pnpm/action-setup@v3 - with: - version: 8 - - name: Setup Node.js environment - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - name: Run bash commands shell: bash run: | ls -alt - # Install deps - pnpm install - # Building package artifact - pnpm pack && mv adguard-github-actions-runner-*.tgz github-actions-runner.tgz + echo "example" > example.txt # Show that secrets are encoded echo "Secret is ${{ secrets.SECRET_KEY }}" - name: Save archived package uses: actions/upload-artifact@v4 with: - name: github-actions-runner.tgz - path: ./github-actions-runner.tgz - - name: Save build.txt - uses: actions/upload-artifact@v4 - with: - name: build.txt - path: ./dist/build.txt + name: example.txt + path: ./example.txt diff --git a/bamboo-specs/example.yaml b/bamboo-specs/example.yaml index bd2aaba..184a4d1 100644 --- a/bamboo-specs/example.yaml +++ b/bamboo-specs/example.yaml @@ -18,7 +18,7 @@ variables: # Using github-actions-runner Docker image for the latest stable version. # latest-ci docker image does not have any entrypoint and has the # runner installed. - dockerNode: ghcr.io/adguardteam/githubactionsrunner:latest-ci + docker: ghcr.io/adguardteam/githubactionsrunner:latest-ci stages: - Test: @@ -32,7 +32,7 @@ Test: other: clean-working-dir: true docker: - image: ${bamboo.dockerNode} + image: ${bamboo.docker} tasks: - checkout: force-clean-build: true @@ -52,12 +52,13 @@ Test: --rev "${bamboo_planRepository_revision}" \ --workflow example.yml \ --artifacts-path . + --secret SECRET_KEY=SECRET_VALUE # The artifacts produced by the workflow are downloaded and shared with the # Bamboo CI job. These artifacts can be then shared with other unrelated # Bamboo builds. artifacts: - - name: github-actions-runner.tgz - pattern: github-actions-runner.tgz + - name: example.txt + pattern: example.txt shared: true required: true requirements: From d5a23c092a38525d3812c30e76fa1a291faa8a89 Mon Sep 17 00:00:00 2001 From: Maxim Topciu Date: Sat, 27 Apr 2024 20:53:15 +0300 Subject: [PATCH 5/5] correct multiple command --- bamboo-specs/example.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bamboo-specs/example.yaml b/bamboo-specs/example.yaml index 184a4d1..3fe8540 100644 --- a/bamboo-specs/example.yaml +++ b/bamboo-specs/example.yaml @@ -51,7 +51,7 @@ Test: --branch "${bamboo_planRepository_branchName}" \ --rev "${bamboo_planRepository_revision}" \ --workflow example.yml \ - --artifacts-path . + --artifacts-path . \ --secret SECRET_KEY=SECRET_VALUE # The artifacts produced by the workflow are downloaded and shared with the # Bamboo CI job. These artifacts can be then shared with other unrelated