diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a4d5922 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,107 @@ +name: CI +on: + pull_request: + push: + branches: + - main + +jobs: + paths: + runs-on: ubuntu-22.04 + timeout-minutes: 5 + outputs: + package: ${{ steps.changes.outputs.package }} + test: ${{ steps.changes.outputs.test }} + + steps: + - run: cat $GITHUB_EVENT_PATH + - uses: dorny/paths-filter@v2.10.2 + id: changes + with: + filters: | + package: + - .github/workflows/package.yml + - dist/** + - src/** + - package-lock.json + - package.json + test: + - .github/workflows/test.yml + + package: + needs: [ paths ] + if: needs.paths.outputs.package == 'true' && github.event_name == 'pull_request' + runs-on: ubuntu-20.04 + timeout-minutes: 5 + + steps: + - id: generate_token + uses: tibdex/github-app-token@v1.6.0 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - uses: actions/checkout@v3 + with: + token: ${{ steps.generate_token.outputs.token }} + ref: ${{ github.head_ref }} + - run: npm install + - run: npm run format + - run: npm run build + - run: npm run lint + - run: npm run package + - name: Diff + id: diff + run: | + git status + git add -N . + git diff --name-only --exit-code + continue-on-error: true + - uses: snow-actions/git-config-user@v1.0.0 + if: steps.diff.outcome == 'failure' + - name: Commit & Push + run: | + git add . + git commit -m 'npm run package' + git push + exit 1 + if: steps.diff.outcome == 'failure' + + test: + needs: [ paths, package ] + if: >- + failure() == false && + cancelled() == false && + (needs.paths.outputs.package == 'true' || needs.paths.outputs.test == 'true') + runs-on: ${{ matrix.os }} + strategy: + matrix: + # Only latest because of API rate limit + os: [ ubuntu-latest, macos-latest, windows-latest ] + steps: + - uses: actions/checkout@v3 + - id: tweet + uses: ./ + env: + CONSUMER_API_KEY: ${{ secrets.CONSUMER_API_KEY }} + CONSUMER_API_SECRET_KEY: ${{ secrets.CONSUMER_API_SECRET_KEY }} + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }} + with: + status: ${{ matrix.os }} ${{ github.job }} ${{ github.run_id }} ${{ github.run_number }} ${{ github.ref }} ${{ github.sha }} + - run: test -n "${ID}" + env: + ID: ${{ fromJSON(steps.tweet.outputs.response).id_str }} + + # Required status checks + passing: + needs: [ test ] + if: always() + runs-on: ubuntu-22.04 + timeout-minutes: 5 + + steps: + - run: echo "$needs" + env: + needs: ${{ toJSON(needs) }} + - run: exit 1 + if: (failure() == false && cancelled() == false) == false # success() || skipped() diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml deleted file mode 100644 index 2d212e5..0000000 --- a/.github/workflows/package.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Package - -on: - pull_request: - paths: - - .github/workflows/package.yml - - dist/** - - src/** - - package-lock.json - - package.json - -jobs: - package: - runs-on: ubuntu-20.04 - timeout-minutes: 5 - - steps: - - id: generate_token - uses: tibdex/github-app-token@v1.6.0 - with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.APP_PRIVATE_KEY }} - - uses: actions/checkout@v3 - with: - token: ${{ steps.generate_token.outputs.token }} - ref: ${{ github.head_ref }} - - run: npm install - - run: npm run format - - run: npm run build - - run: npm run lint - - run: npm run package - - name: Diff - id: diff - run: | - git status - git add -N . - git diff --name-only --exit-code - continue-on-error: true - - uses: snow-actions/git-config-user@v1.0.0 - if: steps.diff.outcome == 'failure' - - name: Commit & Push - run: | - git add . - git commit -m 'npm run package' - git push - if: steps.diff.outcome == 'failure' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index a9a873f..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: 'build-test' -on: - pull_request: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: npm install - - run: npm run all - env: - CONSUMER_API_KEY: ${{ secrets.CONSUMER_API_KEY }} - CONSUMER_API_SECRET_KEY: ${{ secrets.CONSUMER_API_SECRET_KEY }} - ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }} - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - # Only latest because of API rate limit - os: [ ubuntu-latest, macos-latest, windows-latest ] - steps: - - uses: actions/checkout@v3 - - id: tweet - uses: ./ - env: - CONSUMER_API_KEY: ${{ secrets.CONSUMER_API_KEY }} - CONSUMER_API_SECRET_KEY: ${{ secrets.CONSUMER_API_SECRET_KEY }} - ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }} - with: - status: ${{ matrix.os }} ${{ github.job }} ${{ github.run_id }} ${{ github.run_number }} ${{ github.ref }} ${{ github.sha }} - - run: test -n "${ID}" - env: - ID: ${{ fromJSON(steps.tweet.outputs.response).id_str }}