Compile Protos #762
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: Compile Protos | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
workflow_run: | |
workflows: ["On PR Approved"] | |
types: | |
- completed | |
jobs: | |
compile-protos: | |
if: > | |
github.event.workflow_run.event == 'pull_request_review' && | |
github.event.workflow_run.conclusion == 'success' | |
runs-on: [self-hosted, x64] | |
container: | |
image: ghcr.io/viamrobotics/canon:amd64-cache | |
options: --platform linux/amd64 | |
env: | |
CI_COMMIT_MESSAGE_PREFIX: Built new protos from | |
CI_COMMIT_AUTHOR: github-actions | |
LABEL_NAME: protos-compiled | |
steps: | |
# Download PR info from approval workflow and checkout branch | |
- name: Download artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
run_id: ${{github.event.workflow_run.id }} | |
- name: Get PR Repo | |
id: get-pr-repo | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
var fs = require('fs'); | |
var repo = String(fs.readFileSync('./pr/repo')).trim(); | |
return repo | |
- name: Get PR Ref | |
id: get-pr-ref | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
var fs = require('fs'); | |
var ref = String(fs.readFileSync('./pr/ref')).trim(); | |
return ref | |
- name: Get PR Number | |
id: get-pr-number | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
var fs = require('fs'); | |
var number = Number(String(fs.readFileSync('./pr/number')).trim()); | |
return number | |
- uses: actions/checkout@v3 | |
with: | |
repository: ${{ steps.get-pr-repo.outputs.result }} | |
ref: ${{ steps.get-pr-ref.outputs.result }} | |
token: ${{ secrets.REPO_READ_TOKEN }} | |
# Set environment variables based on the last commit | |
- name: Set environment variable "commit-message" | |
run: echo "commit-message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV | |
- name: Set environment variable "commit-author" | |
run: echo "commit-author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV | |
# If the last commit is an auto-generated commit from this workflow, we can exit early | |
- name: Set environment variable "is-auto-commit" | |
if: startsWith(env.commit-message, env.CI_COMMIT_MESSAGE_PREFIX) && env.commit-author == env.CI_COMMIT_AUTHOR | |
run: echo "is-auto-commit=true" >> $GITHUB_ENV | |
# Remove label if exists, since we're about to compile again | |
- name: Remove label | |
if: env.is-auto-commit == false | |
uses: andymckay/[email protected] | |
with: | |
repo-token: ${{ secrets.REPO_READ_TOKEN }} | |
remove-labels: ${{ env.LABEL_NAME }} | |
issue-number: ${{ steps.get-pr-number.outputs.result }} | |
# Build and push | |
- uses: bufbuild/buf-setup-action@v1 | |
if: env.is-auto-commit == false | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: arduino/setup-protoc@v1 | |
if: env.is-auto-commit == false | |
- name: Compile protos | |
if: env.is-auto-commit == false | |
run: make dist/buf | |
- name: Add SHORT_SHA env property | |
if: env.is-auto-commit == false | |
id: short_sha | |
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Commit + Push | |
if: env.is-auto-commit == false | |
uses: EndBug/[email protected] | |
with: | |
default_author: github_actions | |
message: ${{ env.CI_COMMIT_MESSAGE_PREFIX }} ${{ steps.short_sha.outputs.short_sha }} | |
push: true | |
- name: Add label | |
if: env.is-auto-commit == false | |
uses: andymckay/[email protected] | |
with: | |
repo-token: ${{ secrets.REPO_READ_TOKEN }} | |
add-labels: ${{ env.LABEL_NAME }} | |
issue-number: ${{ steps.get-pr-number.outputs.result }} |