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/branch-main-automations.yml b/.github/workflows/branch-main-automations.yml new file mode 100644 index 00000000..99778652 --- /dev/null +++ b/.github/workflows/branch-main-automations.yml @@ -0,0 +1,10 @@ +name: (branch main) Automations + +on: + push: + branches: + - main + +jobs: + 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..6692ccd3 --- /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 58% rename from .github/workflows/package.yml rename to .github/workflows/shared-package-distribution-files.yml index 092ba896..2e9f158e 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/shared-package-distribution-files.yml @@ -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 }} 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();