diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 60822d6..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,41 +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 - - # Linting package - pnpm lint - - # Testing package - pnpm test - # 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 73643f4..3fe8540 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. + docker: ghcr.io/adguardteam/githubactionsrunner:latest-ci stages: - Test: @@ -20,9 +32,7 @@ Test: other: clean-working-dir: true docker: - image: ${bamboo.dockerNode} - volumes: - ${system.PNPM_DIR}: ${bamboo.cachePnpm} + image: ${bamboo.docker} tasks: - checkout: force-clean-build: true @@ -30,26 +40,25 @@ 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 . \ + --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: 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; }