Merge pull request #887 from strukturag/dependabot/go_modules/github.… #176
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: generated | |
on: | |
push: | |
branches: [ master ] | |
paths: | |
- '.github/workflows/generated.yml' | |
- 'api*.go' | |
- '*_easyjson.go' | |
- '*.pb.go' | |
- '*.proto' | |
- 'go.*' | |
pull_request: | |
branches: [ master ] | |
paths: | |
- '.github/workflows/generated.yml' | |
- 'api*.go' | |
- '*_easyjson.go' | |
- '*.pb.go' | |
- '*.proto' | |
- 'go.*' | |
env: | |
CODE_GENERATOR_NAME: struktur AG service user | |
CODE_GENERATOR_EMAIL: opensource@struktur.de | |
permissions: | |
contents: read | |
jobs: | |
check-token: | |
runs-on: ubuntu-latest | |
outputs: | |
token-exists: ${{ steps.token-check.outputs.defined }} | |
steps: | |
- name: Check for Token availability | |
id: token-check | |
# perform secret check & put boolean result as an output | |
shell: bash | |
run: | | |
if [ "${{ secrets.CODE_GENERATOR_PAT }}" != '' ]; then | |
echo "defined=true" >> $GITHUB_OUTPUT; | |
else | |
echo "defined=false" >> $GITHUB_OUTPUT; | |
fi | |
build: | |
name: build | |
runs-on: ubuntu-latest | |
needs: [check-token] | |
if: ${{ github.event_name == 'pull_request' && needs.check-token.outputs.token-exists == 'true' }} | |
permissions: | |
contents: write | |
continue-on-error: true | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.CODE_GENERATOR_PAT }} | |
ref: ${{ github.event.pull_request.head.ref }} | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: "stable" | |
- name: Install dependencies | |
run: | | |
sudo apt -y update && sudo apt -y install protobuf-compiler | |
- name: Generate files | |
run: | | |
make clean-generated | |
make common | |
- name: Commit changes | |
run: | | |
CHECKOUT_SHA=$(git rev-parse HEAD) | |
echo "Checked out $CHECKOUT_SHA" | |
if [ "$CHECKOUT_SHA" != "${{github.event.pull_request.head.sha}}" ]; then | |
echo "More changes since this commit ${{github.event.pull_request.head.sha}}, skipping" | |
else | |
git add *_easyjson.go *.pb.go | |
CHANGES=$(git status --porcelain) | |
if [ -z "$CHANGES" ]; then | |
echo "No files have changed, no need to commit / push." | |
else | |
git config user.name "$CODE_GENERATOR_NAME" | |
git config user.email "$CODE_GENERATOR_EMAIL" | |
git commit --author="$(git log -n 1 --pretty=format:%an) <$(git log -n 1 --pretty=format:%ae)>" -m "Update generated files from ${{github.event.pull_request.head.sha}}" *_easyjson.go *.pb.go | |
git push | |
fi | |
fi | |
check: | |
name: check | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: "stable" | |
- name: Install dependencies | |
run: | | |
sudo apt -y update && sudo apt -y install protobuf-compiler | |
- name: Generate files | |
run: | | |
make clean-generated | |
make common | |
- name: Check generated files | |
run: | | |
git add *.go | |
git diff --cached --exit-code *.go |