Skip to content

Commit

Permalink
Beautified example.yml
Browse files Browse the repository at this point in the history
Merge in CI/github-actions-runner from fix-example to master

* commit 'd5a23c092a38525d3812c30e76fa1a291faa8a89':
  correct multiple command
  simplify example plans
  fix hasCommit method
  remove lint, and test from example
  Beautified example.yml
  • Loading branch information
ameshkov authored and maximtop committed Apr 27, 2024
2 parents 03f9192 + d5a23c0 commit bdac0e8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 51 deletions.
32 changes: 3 additions & 29 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Example workflow for github-actions-runner
name: Example

env:
NODE_VERSION: 20

on:
workflow_dispatch:
inputs:
Expand All @@ -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
41 changes: 25 additions & 16 deletions bamboo-specs/example.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# 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:
project-key: AJL
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:
Expand All @@ -20,36 +32,33 @@ 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
- script:
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:
Expand Down
20 changes: 14 additions & 6 deletions src/lib/github/GithubApiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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;
}
Expand Down

0 comments on commit bdac0e8

Please sign in to comment.