Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub Action workflows #125

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/actions/get-current-branch-name/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Get current branch name
description: Get current branch name for any trigger (workflow_dispatch, pull_request, etc.)

outputs:
branch-name:
description: Branch name
value: ${{ steps.get-branch-name.outputs.branch-name }}

runs:
using: composite
steps:
- name: Get branch name for pull_request trigger
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]];
then
echo "BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}" >> $GITHUB_ENV
fi
exit 0

- name: Get branch name for other triggers
shell: bash
run: |
if [[ "${{ github.event_name }}" != "pull_request" ]] && [[ $GITHUB_REF == refs/heads/* ]];
then
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
exit 0

- name: Get tag name for other triggers
shell: bash
run: |
if [[ "${{ github.event_name }}" != "pull_request" ]] && [[ $GITHUB_REF == refs/tags/* ]];
then
echo "BRANCH_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
fi
exit 0

- name: Set branch name to output
id: get-branch-name
shell: bash
run: echo "##[set-output name=branch-name;]$(echo $BRANCH_NAME)"
10 changes: 10 additions & 0 deletions .github/workflows/branch-main-automations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: (branch main) Automations

on:
push:
branches:
- main

jobs:
package-distribution-files:
uses: ./.github/workflows/shared-package-distribution-files.yml
13 changes: 13 additions & 0 deletions .github/workflows/pr-automations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: (PR) Automations

on:
pull_request:
branches:
- main

jobs:
lint-code:
uses: ./.github/workflows/shared-lint-code.yml

#package-distribution-files:
# uses: ./.github/workflows/shared-package-distribution-files.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
name: PR automations
name: (shared) Lint code

on:
pull_request:
branches:
- main
workflow_call:

jobs:
lint-code:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache dependencies

- name: Cache node_modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ec2-github-runner-${{ hashFiles('**/package-lock.json') }}
key: node-modules-${{ hashFiles('**/package-lock.json') }}

- name: Install packages
run: npm install

- name: Run linter
run: npm run lint
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
on:
push:
branches:
- main
name: (shared) Package distribution files

name: Package
on:
workflow_call:

jobs:
package:
package-distribution-files:
name: Package distribution files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main

- name: Get current branch name
id: get-current-branch-name
uses: ./.github/actions/get-current-branch-name

- name: Install packages
run: npm ci
- name: Run linter
run: npm run lint

- name: Package
run: npm run package

- name: Commit
run: |
git config --global user.name "GitHub Actions"
git add dist/
git commit -m "Update dist" || echo "No changes to commit"
git push origin main
git push origin ${{ steps.get-current-branch-name.outputs.branch-name }}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function setOutput(label, ec2InstanceId) {
core.setOutput('ec2-instance-id', ec2InstanceId);
}

//test
async function start() {
const label = config.generateUniqueLabel();
const githubRegistrationToken = await gh.getRegistrationToken();
Expand Down