Skip to content

Commit a7925c7

Browse files
committed
Reuse workflows and scripts
Refer CI workflows and scripts from .goassets repository instead of copying files.
1 parent 172f4c6 commit a7925c7

31 files changed

+540
-431
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CodeQL
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
analyze:
8+
name: CodeQL
9+
runs-on: ubuntu-latest
10+
permissions:
11+
actions: read
12+
contents: read
13+
security-events: write
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
# The code in examples/ might intentionally do things like log credentials
19+
# in order to show how the library is used, aid in debugging etc. We
20+
# should ignore those for CodeQL scanning, and only focus on the package
21+
# itself.
22+
- name: Remove example code
23+
run: rm -rf examples/
24+
25+
- name: Initialize CodeQL
26+
uses: github/codeql-action/init@v2
27+
with:
28+
languages: 'go'
29+
30+
- name: CodeQL Analysis
31+
uses: github/codeql-action/analyze@v2
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Generate Authors
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
token:
7+
required: true
8+
goassets-ref:
9+
default: master
10+
required: true
11+
type: string
12+
13+
jobs:
14+
check-secret:
15+
name: Check secret
16+
permissions:
17+
contents: none
18+
runs-on: ubuntu-latest
19+
if: startsWith(github.event.pull_request.head.ref, 'renovate/') == false
20+
outputs:
21+
is_token_set: ${{ steps.checksecret_job.outputs.is_token_set }}
22+
steps:
23+
- id: checksecret_job
24+
env:
25+
TOKEN: ${{ secrets.token }}
26+
run: |
27+
echo "is_token_set: ${{ env.TOKEN != '' }}"
28+
echo "::set-output name=is_token_set::${{ env.TOKEN != '' }}"
29+
30+
generate-authors:
31+
name: Generate Authors
32+
permissions:
33+
contents: write
34+
needs: [check-secret]
35+
if: needs.check-secret.outputs.is_token_set == 'true'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v3
39+
with:
40+
ref: ${{ github.head_ref }}
41+
fetch-depth: 0
42+
token: ${{ secrets.token }}
43+
- name: Checkout .goassets
44+
uses: actions/checkout@v3
45+
with:
46+
repository: pion/.goassets
47+
path: ${{ github.workspace }}/.github/.goassets
48+
ref: ${{ inputs.goassets-ref }}
49+
50+
- name: Generate the authors file
51+
run: .github/.goassets/scripts/generate-authors.sh
52+
53+
- name: Add the authors file to git
54+
run: git add AUTHORS.txt
55+
56+
- name: Get last commit message
57+
id: last-commit-message
58+
run: |
59+
COMMIT_MSG=$(git log -1 --pretty=%B)
60+
COMMIT_MSG="${COMMIT_MSG//'%'/'%25'}"
61+
COMMIT_MSG="${COMMIT_MSG//$'\n'/'%0A'}"
62+
COMMIT_MSG="${COMMIT_MSG//$'\r'/'%0D'}"
63+
echo "::set-output name=msg::$COMMIT_MSG"
64+
65+
- name: Get last commit author
66+
id: last-commit-author
67+
run: echo "::set-output name=msg::$(git log -1 --pretty='%aN <%ae>')"
68+
69+
- name: Check if AUTHORS.txt file has changed
70+
id: git-status-output
71+
run: echo "::set-output name=msg::$(git status -s | wc -l)"
72+
73+
- name: Commit and push
74+
if: ${{ steps.git-status-output.outputs.msg != '0' }}
75+
run: |
76+
git config user.email $(echo "${{ steps.last-commit-author.outputs.msg }}" | sed 's/\(.\+\) <\(\S\+\)>/\2/')
77+
git config user.name $(echo "${{ steps.last-commit-author.outputs.msg }}" | sed 's/\(.\+\) <\(\S\+\)>/\1/')
78+
git add AUTHORS.txt
79+
git commit --amend --no-edit
80+
git push --force https://github.com/${GITHUB_REPOSITORY} $(git symbolic-ref -q --short HEAD)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Lint
2+
on:
3+
workflow_call:
4+
inputs:
5+
goassets-ref:
6+
default: master
7+
required: true
8+
type: string
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
lint-commit-message:
15+
name: Metadata
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- name: Checkout .goassets
24+
uses: actions/checkout@v3
25+
with:
26+
repository: pion/.goassets
27+
path: ${{ github.workspace }}/.github/.goassets
28+
ref: ${{ inputs.goassets-ref }}
29+
30+
- name: Commit Message
31+
run: .github/.goassets/scripts/lint-commit-message.sh
32+
33+
- name: File names
34+
run: .github/.goassets/scripts/lint-filename.sh
35+
36+
- name: Functions
37+
run: .github/.goassets/scripts/lint-disallowed-functions-in-library.sh
38+
39+
- name: Logging messages should not have trailing newlines
40+
run: .github/.goassets/scripts/lint-no-trailing-newline-in-log-messages.sh
41+
42+
lint-go:
43+
name: Go
44+
permissions:
45+
contents: read
46+
pull-requests: read
47+
runs-on: ubuntu-latest
48+
strategy:
49+
fail-fast: false
50+
steps:
51+
- uses: actions/checkout@v3
52+
53+
- name: golangci-lint
54+
uses: golangci/golangci-lint-action@v3
55+
with:
56+
version: v1.45.2
57+
args: $GOLANGCI_LINT_EXRA_ARGS

.github/workflows/lint.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
name: Lint
22
on:
33
pull_request:
4-
types:
5-
- opened
6-
- edited
7-
- synchronize
4+
85
jobs:
96
commit-lint:
107
runs-on: ubuntu-latest
118
steps:
12-
- name: checkout
9+
- name: Checkout
1310
uses: actions/checkout@v3
1411
with:
1512
fetch-depth: 0
16-
- name: copy scripts
17-
run: cp ci/.github/*.sh .github/
18-
- name: lint commit message
19-
run: .github/lint-commit-message.sh
13+
- name: Copy scripts
14+
run: |
15+
mkdir -p .github/.goassets/
16+
cp -r scripts/lint-commit-message.sh .github/.goassets/
17+
- name: Lint commit message
18+
run: .github/.goassets/lint-commit-message.sh
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release
2+
on:
3+
workflow_call:
4+
inputs:
5+
go-version:
6+
required: true
7+
type: string
8+
9+
jobs:
10+
release:
11+
name: Release
12+
permissions:
13+
contents: write
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- uses: actions/setup-go@v3
20+
with:
21+
go-version: ${{ inputs.go-version }}
22+
- name: Build and release
23+
uses: goreleaser/goreleaser-action@v4
24+
with:
25+
version: latest
26+
args: release --rm-dist
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Fix go.sum
2+
on:
3+
workflow_call:
4+
secrets:
5+
token:
6+
required: true
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
fix:
13+
name: Fix go.sum
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 2
19+
- name: Fix
20+
uses: at-wat/go-sum-fix-action@v0
21+
with:
22+
git_user: Pion Bot
23+
git_email: 59523206+pionbot@users.noreply.github.com
24+
github_token: ${{ secrets.token }}
25+
commit_style: squash
26+
push: force
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test i386
2+
on:
3+
workflow_call:
4+
inputs:
5+
go-version:
6+
required: true
7+
type: string
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test-i386:
14+
runs-on: ubuntu-latest
15+
name: Go i386 ${{ inputs.go-version }}
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- uses: actions/cache@v3
20+
with:
21+
path: |
22+
~/go/pkg/mod
23+
~/.cache
24+
key: ${{ runner.os }}-i386-go-${{ hashFiles('**/go.sum') }}
25+
restore-keys: ${{ runner.os }}-i386-go-
26+
27+
- name: Run test
28+
run: |
29+
mkdir -p $HOME/go/pkg/mod $HOME/.cache
30+
docker run \
31+
-u $(id -u):$(id -g) \
32+
-e "GO111MODULE=on" \
33+
-e "CGO_ENABLED=0" \
34+
-v $GITHUB_WORKSPACE:/go/src/github.com/pion/$(basename $GITHUB_WORKSPACE) \
35+
-v $HOME/go/pkg/mod:/go/pkg/mod \
36+
-v $HOME/.cache:/.cache \
37+
-w /go/src/github.com/pion/$(basename $GITHUB_WORKSPACE) \
38+
i386/golang:${{inputs.go-version}}-alpine \
39+
/usr/local/go/bin/go test \
40+
${TEST_EXTRA_ARGS:-} \
41+
-v ./...
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Test WASM
2+
on:
3+
workflow_call:
4+
inputs:
5+
go-version:
6+
required: true
7+
type: string
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test-wasm:
14+
runs-on: ubuntu-latest
15+
name: WASM
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '16.x'
23+
24+
- uses: actions/cache@v3
25+
with:
26+
path: |
27+
~/go/pkg/mod
28+
~/.cache
29+
key: ${{ runner.os }}-wasm-go-${{ hashFiles('**/go.sum') }}
30+
restore-keys: ${{ runner.os }}-wasm-go-
31+
32+
- name: Download Go
33+
run: curl -sSfL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar -C ~ -xzf -
34+
env:
35+
GO_VERSION: ${{ inputs.go-version }}
36+
37+
- name: Set Go Root
38+
run: echo "GOROOT=${HOME}/go" >> $GITHUB_ENV
39+
40+
- name: Set Go Path
41+
run: echo "GOPATH=${HOME}/go" >> $GITHUB_ENV
42+
43+
- name: Set Go Path
44+
run: echo "GO_JS_WASM_EXEC=${GOROOT}/misc/wasm/go_js_wasm_exec" >> $GITHUB_ENV
45+
46+
- name: Insall NPM modules
47+
run: yarn install
48+
49+
- name: Run Tests
50+
run: |
51+
if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi
52+
GOOS=js GOARCH=wasm $GOPATH/bin/go test \
53+
-coverprofile=cover.out -covermode=atomic \
54+
-exec="${GO_JS_WASM_EXEC}" \
55+
-v ./...
56+
57+
- uses: codecov/codecov-action@v3
58+
with:
59+
name: codecov-umbrella
60+
fail_ci_if_error: true
61+
flags: wasm

0 commit comments

Comments
 (0)