feat!: initial implementation of the lib-streamproc package #6
Workflow file for this run
This file contains 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
name: PR CI | |
on: | |
pull_request: | |
branches: [ develop, main ] | |
env: | |
GO111MODULE: on | |
GO_VERSION: 1.19 | |
NODE_VERSION: 22 | |
LINT_ARGS: -v --timeout 5m0s --out-${NO_FUTURE}format colored-line-number | |
TEST_ARGS: -v -short -coverprofile=coverage.out | |
TEST_PATH: ./... | |
jobs: | |
commitlint: | |
name: Commit Lint Job | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install commitlint | |
run: | | |
npm install --save-dev @commitlint/{cli,config-conventional} | |
- name: Validate PR commits with commitlint | |
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose | |
editor_config_job: | |
name: Editor Config Job | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Editor Config | |
run: | | |
npm install --save-dev editorconfig-checker | |
./node_modules/.bin/editorconfig-checker | |
lint_job: | |
name: Go Lint Job | |
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Tidy | |
run: go mod tidy | |
- name: Go Lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: v1.50.0 | |
args: ${{ env.LINT_ARGS }} | |
skip-pkg-cache: true | |
skip-build-cache: true | |
licenses_check: | |
name: 3rd Party Licenses Check | |
if: ${{ github.event.head_commit.committer.name != 'github-actions[bot]' || ! contains(github.head_ref, 'release-please--branches--main') }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Retrieve PR and branch info | |
run: | | |
PR_TITLE="chore: update 3rd-party licenses (#${{ github.event.number }})" | |
PR_INFO=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/pulls?state=open" | \ | |
jq --arg TITLE "$PR_TITLE" '.[] | select(.title == $TITLE) | { number: .number, head: .head.ref }') | |
echo "PR_INFO=$PR_INFO" | |
PR_NUMBER=$(echo "$PR_INFO" | jq -r .number) | |
BRANCH_NAME=$(echo "$PR_INFO" | jq -r .head) | |
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV | |
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
echo "BRANCH_NAME=${BRANCH_NAME:-update-third-party-licenses-${{ github.run_id }}}" >> $GITHUB_ENV | |
echo "PARENT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
# if PR already exists | |
- name: Pull latest changes to existing branch | |
if: env.PR_NUMBER != '' | |
run: | | |
git fetch origin | |
git switch ${{ env.BRANCH_NAME }} | |
git pull origin ${{ env.PARENT_BRANCH }} --no-rebase | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Tidy | |
run: go mod tidy | |
- name: Vendor | |
run: go mod vendor | |
- name: Install Go licenses | |
run: go install github.com/google/[email protected] | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
cache: 'pip' | |
cache-dependency-path: '.github/workflows/requirements.txt' | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r .github/workflows/requirements.txt | |
- name: Run license check | |
run: | | |
go-licenses report ./... 2>/dev/null | python .github/workflows/generate_and_check_licenses.py | |
- name: Check and Commit changes | |
run: | | |
if [ -d "./licenses" ]; then | |
git add ./licenses | |
fi | |
if ! git diff-index --quiet HEAD; then | |
git commit -m "chore: update third party licenses" | |
echo "changes_committed=true" >> $GITHUB_ENV | |
else | |
echo "changes_committed=false" >> $GITHUB_ENV | |
fi | |
# This will fail if the incorrect go.mod or go.sum is committed | |
- name: Push changes | |
if: env.changes_committed == 'true' | |
run: | | |
git diff | |
if [[ -z "$PR_NUMBER" ]]; then | |
git switch -c ${{ env.BRANCH_NAME }} | |
fi | |
git push origin HEAD | |
- name: Create new PR | |
if: env.changes_committed == 'true' && env.PR_NUMBER == '' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
echo "Creating a new PR..." | |
gh pr create --base "${{ env.PARENT_BRANCH }}" --head "update-third-party-licenses-${{ github.run_id }}" --title "${{ env.PR_TITLE }}" --body "This is an automated PR that updates the list of 3rd party licenses." | |
test_job: | |
name: Test Job | |
if: ${{ github.base_ref == 'main' && ! contains(github.head_ref, 'release-please--branches--main') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Tidy | |
run: go mod tidy | |
- name: Go Test | |
run: go test ${{ env.TEST_ARGS }} ${{ env.TEST_PATH }} |