From e9f4178283334702013926fe114f518cda100ed7 Mon Sep 17 00:00:00 2001 From: Volodymyr Machula Date: Thu, 10 Nov 2022 19:02:55 +0100 Subject: [PATCH 1/5] Update GitHub Action workflows --- .github/workflows/branch-main-automations.yml | 13 +++++++++++++ .github/workflows/pr-automations.yml | 13 +++++++++++++ .../workflows/{pr.yml => shared-lint-code.yml} | 15 +++++++++------ ....yml => shared-package-distribution-files.yml} | 15 +++++++-------- 4 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/branch-main-automations.yml create mode 100644 .github/workflows/pr-automations.yml rename .github/workflows/{pr.yml => shared-lint-code.yml} (65%) rename .github/workflows/{package.yml => shared-package-distribution-files.yml} (81%) diff --git a/.github/workflows/branch-main-automations.yml b/.github/workflows/branch-main-automations.yml new file mode 100644 index 00000000..b6bb8a48 --- /dev/null +++ b/.github/workflows/branch-main-automations.yml @@ -0,0 +1,13 @@ +name: (branch main) Automations + +on: + push: + branches: + - main + +jobs: + lint-code: + uses: ./.github/workflows/shared-lint-code.yml + + package-distribution-files: + uses: ./.github/workflows/shared-package-distribution-files.yml diff --git a/.github/workflows/pr-automations.yml b/.github/workflows/pr-automations.yml new file mode 100644 index 00000000..3ca07df6 --- /dev/null +++ b/.github/workflows/pr-automations.yml @@ -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 diff --git a/.github/workflows/pr.yml b/.github/workflows/shared-lint-code.yml similarity index 65% rename from .github/workflows/pr.yml rename to .github/workflows/shared-lint-code.yml index f98cc71b..8781c73d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/shared-lint-code.yml @@ -1,8 +1,8 @@ -name: PR automations +name: (shared) Lint code + on: - pull_request: - branches: - - main + workflow_call: + jobs: lint-code: name: Lint code @@ -10,12 +10,15 @@ jobs: 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 diff --git a/.github/workflows/package.yml b/.github/workflows/shared-package-distribution-files.yml similarity index 81% rename from .github/workflows/package.yml rename to .github/workflows/shared-package-distribution-files.yml index 092ba896..da3250ef 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/shared-package-distribution-files.yml @@ -1,12 +1,10 @@ -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: @@ -14,12 +12,13 @@ jobs: uses: actions/checkout@v3 with: ref: main + - 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" From b3ff2cc900f244a49f953a71d8615caafb87adf2 Mon Sep 17 00:00:00 2001 From: Volodymyr Machula Date: Thu, 10 Nov 2022 19:06:02 +0100 Subject: [PATCH 2/5] Test --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 00bc5152..4bcf48f0 100644 --- a/src/index.js +++ b/src/index.js @@ -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(); From 750ee843972444d51e3d12870535b371bc47c1f6 Mon Sep 17 00:00:00 2001 From: Volodymyr Machula Date: Thu, 10 Nov 2022 19:18:34 +0100 Subject: [PATCH 3/5] Update actions --- .../get-current-branch-name/action.yml | 42 +++++++++++++++++++ .../shared-package-distribution-files.yml | 8 +++- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .github/actions/get-current-branch-name/action.yml diff --git a/.github/actions/get-current-branch-name/action.yml b/.github/actions/get-current-branch-name/action.yml new file mode 100644 index 00000000..bb85fd68 --- /dev/null +++ b/.github/actions/get-current-branch-name/action.yml @@ -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)" diff --git a/.github/workflows/shared-package-distribution-files.yml b/.github/workflows/shared-package-distribution-files.yml index da3250ef..568773f7 100644 --- a/.github/workflows/shared-package-distribution-files.yml +++ b/.github/workflows/shared-package-distribution-files.yml @@ -8,10 +8,14 @@ jobs: name: Package distribution files runs-on: ubuntu-latest steps: + - name: Get current branch name + id: get-current-branch-name + uses: ./.github/actions/get-current-branch-name + - name: Checkout uses: actions/checkout@v3 with: - ref: main + ref: ${{ steps.get-current-branch-name.outputs.branch-name }} - name: Install packages run: npm ci @@ -24,4 +28,4 @@ jobs: 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 }} From 365e2b08b26fe88ce73cb3aacecda8fb83d694e8 Mon Sep 17 00:00:00 2001 From: Volodymyr Machula Date: Thu, 10 Nov 2022 19:20:26 +0100 Subject: [PATCH 4/5] Update actions --- .github/workflows/shared-package-distribution-files.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/shared-package-distribution-files.yml b/.github/workflows/shared-package-distribution-files.yml index 568773f7..2e9f158e 100644 --- a/.github/workflows/shared-package-distribution-files.yml +++ b/.github/workflows/shared-package-distribution-files.yml @@ -8,15 +8,13 @@ jobs: name: Package distribution files runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Get current branch name id: get-current-branch-name uses: ./.github/actions/get-current-branch-name - - name: Checkout - uses: actions/checkout@v3 - with: - ref: ${{ steps.get-current-branch-name.outputs.branch-name }} - - name: Install packages run: npm ci From 27b93ea8ee355fe4111dd0ff691926ded5a0c2e8 Mon Sep 17 00:00:00 2001 From: Volodymyr Machula Date: Thu, 10 Nov 2022 19:23:47 +0100 Subject: [PATCH 5/5] Update --- .github/workflows/branch-main-automations.yml | 3 --- .github/workflows/pr-automations.yml | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/branch-main-automations.yml b/.github/workflows/branch-main-automations.yml index b6bb8a48..99778652 100644 --- a/.github/workflows/branch-main-automations.yml +++ b/.github/workflows/branch-main-automations.yml @@ -6,8 +6,5 @@ on: - main jobs: - lint-code: - uses: ./.github/workflows/shared-lint-code.yml - package-distribution-files: uses: ./.github/workflows/shared-package-distribution-files.yml diff --git a/.github/workflows/pr-automations.yml b/.github/workflows/pr-automations.yml index 3ca07df6..6692ccd3 100644 --- a/.github/workflows/pr-automations.yml +++ b/.github/workflows/pr-automations.yml @@ -9,5 +9,5 @@ jobs: lint-code: uses: ./.github/workflows/shared-lint-code.yml - package-distribution-files: - uses: ./.github/workflows/shared-package-distribution-files.yml + #package-distribution-files: + # uses: ./.github/workflows/shared-package-distribution-files.yml