From a4533e74c3e7b8e11bfc18ed5c1730469bcb895c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Steenis Date: Mon, 13 Dec 2021 19:50:25 +0100 Subject: [PATCH] Add GitHub Actions workflow for go-generate --- .github/workflows/git-actions-go-generate.yml | 62 +++++++++++++++++++ Dockerfile.dapper | 2 +- scripts/go-generate | 2 + 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/git-actions-go-generate.yml create mode 100755 scripts/go-generate diff --git a/.github/workflows/git-actions-go-generate.yml b/.github/workflows/git-actions-go-generate.yml new file mode 100644 index 00000000..40c8c213 --- /dev/null +++ b/.github/workflows/git-actions-go-generate.yml @@ -0,0 +1,62 @@ +name: Go Generate +on: workflow_dispatch +permissions: + contents: write + pull-requests: write +jobs: + go-generate: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v2 + - name: Run go-generate to fetch data.json + run: make go-generate + - name: Check for repository changes + run: | + if git diff --name-only --exit-code; then + echo "No changes found in repository after 'go generate'" + echo "changes_exist=false" >> $GITHUB_ENV + else + echo "Changes found in repository after 'go generate':" + git diff --name-only + echo "changes_exist=true" >> $GITHUB_ENV + fi + - name: Create branch, commit and push + if: ${{ env.changes_exist == 'true' }} + id: branch + run: | + BRANCH="githubaction-go-generate-$(date +%Y-%m-%d-%H-%M-%S)" + echo "::set-output name=branch::$BRANCH" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git checkout -b "$BRANCH" + git commit -a -m 'go generate' + git push origin "$BRANCH" + - name: Create Pull Request + if: ${{ env.changes_exist == 'true' }} + id: cpr + uses: actions/github-script@v5.0.0 + env: + SOURCE_BRANCH: ${{ steps.branch.outputs.branch }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { data: pr } = await github.rest.pulls.create({ + title: "[${{ github.ref_name }}] go generate", + body: 'Auto-generated by GitHub Actions', + owner: context.repo.owner, + repo: context.repo.repo, + base: "${{ github.ref_name }}", + head: `${ process.env.SOURCE_BRANCH }` + }); + await github.rest.issues.addLabels({ + ...context.repo, + issue_number: pr.number, + labels: ["status/auto-created"], + }); + console.log('Created new pull request'); + return pr.html_url; + - name: Check outputs + if: ${{ env.changes_exist == 'true' }} + run: | + echo "Pull Request URL - ${{ steps.cpr.outputs.result }}" diff --git a/Dockerfile.dapper b/Dockerfile.dapper index dfdbc1d2..2d0f42ae 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -24,7 +24,7 @@ RUN wget -O - ${!DOCKER_URL} > /usr/bin/docker && chmod +x /usr/bin/docker ENV DAPPER_SOURCE /go/src/github.com/rancher/rke/ ENV DAPPER_RUN_ARGS --privileged -v /var/lib/docker -ENV DAPPER_OUTPUT ./bin ./dist ./build/bin +ENV DAPPER_OUTPUT ./bin ./dist ./build/bin ./data ENV DAPPER_DOCKER_SOCKET true ENV DAPPER_ENV TAG REPO GOOS CROSS DRONE_TAG ENV HOME ${DAPPER_SOURCE} diff --git a/scripts/go-generate b/scripts/go-generate new file mode 100755 index 00000000..e5ece0c2 --- /dev/null +++ b/scripts/go-generate @@ -0,0 +1,2 @@ +#!/bin/bash +go generate