ci: Modernize GitHub Actions workflows #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Continous Integration | |
| name: ci | |
| on: [ push, pull_request ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.9 | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.9 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: | | |
| pip install --upgrade pip setuptools | |
| pip install pre-commit | |
| npm ci --include=optional | |
| npm run build | |
| - name: Run Linting | |
| run: | | |
| pre-commit run --all-files --verbose | |
| os_build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - macos-13 | |
| python: [ "3.10", "3.11", "3.12"] | |
| node: [ 20 ] | |
| env: | |
| SAM_CLI_TELEMETRY: "0" | |
| AWS_REGION: "us-east-1" | |
| AWS_DEFAULT_REGION: "us-east-1" | |
| AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE" | |
| AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | |
| LOG_PATH: /tmp/debug-logs | |
| PIP_LOG_FILE: /tmp/pip.log | |
| HOMEBREW_NO_AUTO_UPDATE: 1 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Update Homebrew and save docker version | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew tap homebrew/core | |
| cat "$(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/d/docker.rb" > .github/brew-formulae | |
| - name: Configure Homebrew docker cache files | |
| uses: actions/cache@v4 | |
| if: runner.os == 'macOS' | |
| with: | |
| path: | | |
| ~/Library/Caches/Homebrew/docker--* | |
| ~/Library/Caches/Homebrew/downloads/*--docker-* | |
| key: brew-${{ hashFiles('.github/brew-formulae') }} | |
| restore-keys: brew- | |
| - name: Install Docker if on MacOS and start colima | |
| id: install_mac_docker | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew install docker --cask | |
| brew install colima | |
| colima start | |
| echo "DOCKER_HOST=unix://$HOME/.colima/default/docker.sock" >> $GITHUB_ENV | |
| docker ps | |
| docker --version | |
| colima status | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python }} | |
| cache: 'pip' | |
| - name: Install Dependencies Python | |
| id: install_python | |
| run: | | |
| mkdir "$LOG_PATH" | |
| pip install --upgrade pip | |
| pip install --upgrade setuptools wheel aws-sam-cli -r https://raw.githubusercontent.com/aws-cloudformation/cloudformation-cli/master/requirements.txt | |
| pip install . | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node }} | |
| cache: 'npm' | |
| - name: Install Dependencies Node.js | |
| id: install_nodejs | |
| run: | | |
| npm ci --include=optional | |
| find ./node_modules/* -mtime +10950 -exec touch {} \; | |
| npm run build | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pre-commit/ | |
| key: ${{ matrix.os }}-${{ env.pythonLocation }}${{ hashFiles('.pre-commit-config.yaml') }} | |
| - name: Run Unit Tests | |
| id: unit_testing | |
| run: | | |
| pre-commit run --all-files --verbose | |
| - name: Upload Coverage | |
| id: codecov | |
| run: | | |
| curl -s https://codecov.io/bash > codecov.sh | |
| bash codecov.sh -f coverage/py/coverage.xml -F unittests -n codecov-python | |
| bash codecov.sh -f coverage/ts/coverage-final.json -F unittests -n codecov-typescript | |
| - name: Upload Coverage Artifacts | |
| id: upload_coverage | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-${{ matrix.os }}-py${{ matrix.python }} | |
| path: coverage/ | |
| - name: Run Integration Tests | |
| id: integration_testing | |
| run: | | |
| RPDK_PACKAGE=$(npm pack --silent) | |
| RPDK_PATH=$PWD/$RPDK_PACKAGE | |
| DIR=TestCI | |
| mkdir $DIR | |
| cd "$DIR" | |
| echo "PROJECT_DIR=$PWD" >> $GITHUB_ENV | |
| ls -la | |
| printf "n" | cfn init -vv --artifact-type RESOURCE --type-name AWS::Foo::Bar typescript | |
| ls -la | |
| mkdir ./dist | |
| cp "$RPDK_PATH" ./dist | |
| npm install "./dist/$RPDK_PACKAGE" | |
| cfn generate -vv && cfn validate -vv | |
| npm install --include=optional | |
| sam build --debug --build-dir ./build TypeFunction | |
| sam build --debug --build-dir ./build TestEntrypoint | |
| sam local invoke -t ./build/template.yaml --debug --event ./sam-tests/create.json --log-file ./sam.log TestEntrypoint | |
| grep -q '"SUCCESS"' sam.log | |
| - name: Gather Debug Logs | |
| id: gather_logs | |
| continue-on-error: true | |
| if: failure() | |
| run: | | |
| mkdir "$LOG_PATH/_logs" 2>&1 || : | |
| cp -r "$(npm config get cache)/_logs" "$LOG_PATH" 2>&1 || : | |
| cp "$GITHUB_WORKSPACE/npm-debug.log" "$LOG_PATH/_logs" 2>&1 || : | |
| cp "$PROJECT_DIR/npm-debug.log" "$LOG_PATH/_logs" 2>&1 || : | |
| cp "$PIP_LOG_FILE" "$LOG_PATH" 2>&1 || : | |
| cp "$PROJECT_DIR/rpdk.log" "$LOG_PATH" 2>&1 || : | |
| cp "$PROJECT_DIR/sam.log" "$LOG_PATH" 2>&1 || : | |
| - name: Upload Debug Artifacts | |
| id: upload_logs | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: debug-logs-${{ matrix.os }}-py${{ matrix.python }} | |
| path: ${{ env.LOG_PATH }} |