Skip to content

fix: Periodic workflow errors #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions .github/workflows/update-all-lint-rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ concurrency:
cancel-in-progress: true

env:
branch: "update-all-lint-rules"
branch: "update-all-lint-rules-${{ github.run_number }}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a different branch each time.


jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
has_diff: ${{ steps.output.outputs.has_diff }}
has_diff: ${{ steps.check_diff.outputs.has_diff }}
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
Expand All @@ -29,48 +29,49 @@ jobs:
--file "../altive_lints/lib/all_lint_rules.yaml" \
--query-selector "pre code" \
--verbose
- name: output diff
id: output
run: echo "diff_count=$(git diff --name-only --relative=packages/altive_lints/lib | wc -l)" >> "$GITHUB_ENV"
- name: Create branch
if: env.diff_count != '0'
- name: Check for changes
id: check_diff
run: |
git switch -c ${{ env.branch }}
git push origin ${{ env.branch }}
- name: Git config
diff_count=$(git diff --name-only --relative=packages/altive_lints/lib | wc -l)
echo "diff_count=$diff_count" >> "$GITHUB_ENV"
if [ "$diff_count" -ne "0" ]; then
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Create branch, configure git, commit & push
if: env.diff_count != '0'
run: |
git remote set-url origin "https://github-actions:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}"
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Commit & Push
if: env.diff_count != '0'
run: |
git switch -c ${{ env.branch }}
git add .
git commit -m "feat: update all_lint_rules"
git push origin ${{ env.branch }}
- name: Output flag
run: echo "has_diff=${{ env.diff_count != '0' }}" >> "$GITHUB_OUTPUT"

pull-request:
name: Create Pull-Request
runs-on: ubuntu-latest
needs: [update]
if: ${{ needs.update.outputs.has_diff == 'true' }}
needs: update
if: needs.update.outputs.has_diff == 'true'
steps:
- uses: actions/checkout@v4
- name: Generate GiHub App token
- name: Generate GitHub App token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.PR_WRITER_APP_ID }}
private-key: ${{ secrets.PR_WRITER_PRIVATE_KEY }}

- name: Create PR
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: gh pr create -B "$GITHUB_REF" -t "${{ env.branch }}" -b "" -a "$GITHUB_ACTOR" -H "${{ env.branch }}"

run: |
gh pr create \
--base "$GITHUB_REF" \
--head ${{ env.branch }} \
--title "feat: Update all lint rules" \
--body "Automated pull request to update lint rules." \
--assignee "$GITHUB_ACTOR"
- name: Revoke GitHub Apps token
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
Expand Down