Skip to content

Commit

Permalink
fix: various fixes (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonraid authored Aug 31, 2022
1 parent c53a234 commit 2ac7a0f
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 21 deletions.
32 changes: 26 additions & 6 deletions .github/workflows/build_docker_image_and_push_to_ecr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ on:
required: true
type: string
setNodeVersion:
description: Put NODE_VERSION from .nvmrc to GITHUB_ENV
description: Put NODE_VERSION from .nvmrc to docker build args
required: false
type: string
default: "yes"
default: true
dockerBuildArgs:
description: Values for --build-arg argument
required: false
type: string
# This is just a dummy default, so docker does not complain
default: FOO=BAR
actorOverride:
description: Override the author of event
required: false
Expand All @@ -49,12 +55,17 @@ on:
slackToken:
description: Slack API token
required: true
npmToken:
description: Put NPM_TOKEN to docker build args
required: false

env:
AWS_ACCESS_KEY_ID: ${{ secrets.awsAccessKeyId }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.awsSecretAccessKey }}
AWS_REGION: ${{ inputs.awsRegion }}

# NPMRC_TEMP_FILE: npmrc-temp-file

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -101,9 +112,16 @@ jobs:
- name: clone repository
uses: actions/checkout@v3

- name: initialize
if: inputs.setNodeVersion == 'yes'
run: echo "NODE_VERSION=$(head -1 .nvmrc)" >> $GITHUB_ENV
- name: set docker build args and secrets
run: |
BUILD_ARGS=${{ inputs.dockerBuildArgs }}
if [ "${{ inputs.setNodeVersion }}" = true ]; then
BUILD_ARGS="${BUILD_ARGS}\nNODE_VERSION=$(head -1 .nvmrc)"
fi
echo 'BUILD_ARGS<<EOF' >> $GITHUB_ENV
echo -e ${BUILD_ARGS} >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
# NOTE: can be useful
# - name: Set up QEMU
Expand All @@ -126,7 +144,9 @@ jobs:
file: ${{ inputs.dockerFilePath }}
push: true
tags: ${{ inputs.registry }}/${{ inputs.repository }}:${{ inputs.imageTag }}
build-args: NODE_VERSION=${{ env.NODE_VERSION }}
build-args: |
${{ env.BUILD_ARGS }}
NPM_TOKEN=${{ secrets.npmToken }}
- name: helper - get slack message attachment color
id: helper
Expand Down
34 changes: 19 additions & 15 deletions .github/workflows/get_values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,43 @@ on:
description: Commit SHA
required: false
type: string
default: ${{ github.event.pull_request.head.sha }}

outputs:
short_commit_sha:
description: Short commit sha
value: ${{ jobs.get_short_commit_sha.outputs.short_commit_sha }}
value: ${{ jobs.get_values.outputs.short_commit_sha }}
commit_author:
description: Author of give commit
value: ${{ jobs.get_commit_author.outputs.commit_author }}
description: Author of last commit
value: ${{ jobs.get_values.outputs.commit_author }}

jobs:
get_short_commit_sha:
get_values:
runs-on: ubuntu-latest
outputs:
short_commit_sha: ${{ steps.get_short_commit_sha.outputs.short_commit_sha }}
commit_author: ${{ steps.get_commit_author.outputs.result }}
steps:
# Cannot use GITHUB_SHA because of https://github.community/t/github-sha-not-the-same-as-the-triggering-commit/18286/2
- id: get_short_commit_sha
- name: get short commit sha
id: get_short_commit_sha
run: |
COMMIT_SHA=${{ inputs.commitSha }}
if [ "${{ inputs.commitSha }}" != "" ]; then
COMMIT_SHA=${{ inputs.commitSha }}
elif [ "${{ github.event_name }}" = "pull_request" ]; then
COMMIT_SHA=${{ github.event.pull_request.head.sha }}
else
COMMIT_SHA=${{ github.sha }}
fi
echo "SHORT_COMMIT_SHA=${COMMIT_SHA::10}" >> $GITHUB_ENV
echo "::set-output name=short_commit_sha::${COMMIT_SHA::10}"
get_commit_author:
runs-on: ubuntu-latest
outputs:
commit_author: ${{ steps.get_commit_author.outputs.result }}
steps:
- uses: actions/github-script@v6
- name: get last commit author
uses: actions/github-script@v6
id: get_commit_author
with:
result-encoding: string
script: |
const commitSha = '${{ inputs.commitSha }}';
const commitSha = process.env.SHORT_COMMIT_SHA;
if (!commitSha) throw new Error(`Input: "commitSha" has invalid value ${commitSha}`)
const payload = await github.rest.repos.getCommit({
Expand All @@ -49,4 +53,4 @@ jobs:
ref: commitSha,
});
return payload.data.author.login;
return payload.data.author.login;
185 changes: 185 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: run tests

on:
workflow_call:
inputs:
# TODO: All these inputs are not entirely necessary, they are just there for convenience of "setup Node.js" step,
# where they are required. Making them optional requires additional logic, that might be un-necessary for our purposes
# Best would be if "actions/setup-node" would be able to parse these from .npmrc and .nvmrc (except token of course)
npmAuth:
description: Whether to authenticate to NPM registry
required: false
type: boolean
default: true
nodeVersionFile:
description: Path to node version file
required: false
type: string
default: .nvmrc
npmRegistryUrl:
description: NPM registry url
required: false
type: string
default: https://npm.pkg.github.com/
npmScope:
description: NPM scope
required: true
type: string
npmTestScript:
description: Script for test in package.json
required: true
type: string
title:
description: Title displayed in slack message
required: false
type: string
default: "integration tests"
revision:
description: Revision that is being tested (This is strictly informative)
required: true
type: string
slackChannelId:
description: Slack Channel ID
required: true
type: string
actorOverride:
description: Override the author of event
required: false
type: string
envVariables:
description: Space separated list of environment variables to be set during test phase
required: false
type: string
# example:
# envVariables: >
# FOO=bar
# BAR=foo

secrets:
npmToken:
description: NPM token
required: false
slackToken:
description: Slack API token
required: true


jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Send notification to slack
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.slackToken }}
with:
channel-id: ${{ inputs.slackChannelId }}
payload: |
{
"text": ":large_blue_circle: *${{ github.repository }} ${{ inputs.title }} started*",
"attachments": [
{
"color": "#0066ff",
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Author:* ${{ inputs.actorOverride || github.actor }}"
},
{
"type": "mrkdwn",
"text": "*Revision:* ${{ inputs.revision }}"
},
{
"type": "mrkdwn",
"text": "*Details:* <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|trigger>, <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>"
},
{
"type": "mrkdwn",
"text": "*Triggered by:* ${{ github.event_name }}"
}
]
}
]
}
]
}
- name: clone local repository
uses: actions/checkout@v3

# TODO: turn on caching
- name: setup Node.js
uses: actions/setup-node@v3
with:
always-auth: ${{ inputs.npmAuth }}
node-version-file: ${{ inputs.nodeVersionFile }}
registry-url: ${{ inputs.npmRegistryUrl }}
scope: ${{ inputs.npmScope }}

- name: run tests
run: |
if [ "${{ inputs.envVariables }}" != "" ]; then
export $(echo ${{ inputs.envVariables }})
fi
if [ "${{ secrets.npmToken }}" != "" ]; then
export NODE_AUTH_TOKEN=${{ secrets.npmToken }}
fi
npm install
npm run ${{ inputs.npmTestScript }}
- name: helper - get slack message formatting
id: helper
if: ${{ always() }}
run: |
if [ "${{ job.status }}" = "success" ]
then
echo ::set-output name=color::#00cc00
echo ::set-output name=emoji::large_green_circle
else
echo ::set-output name=color::#ff0000
echo ::set-output name=emoji::red_circle
fi
- name: send result to slack
if: ${{ always() }}
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.slackToken }}
with:
channel-id: ${{ inputs.slackChannelId }}
payload: |
{
"text": ":${{ steps.helper.outputs.emoji }}: *${{ github.repository }} ${{ inputs.title }} result: ${{ job.status }}*",
"attachments": [
{
"color": "${{ steps.helper.outputs.color }}",
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Author:* ${{ inputs.actorOverride || github.actor }}"
},
{
"type": "mrkdwn",
"text": "*Revision:* ${{ inputs.revision }}"
},
{
"type": "mrkdwn",
"text": "*Details:* <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|trigger>, <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>"
},
{
"type": "mrkdwn",
"text": "*Triggered by:* ${{ github.event_name }}"
}
]
}
]
}
]
}

0 comments on commit 2ac7a0f

Please sign in to comment.