Skip to content

Commit

Permalink
Merge pull request #431 from scala-steward-org/build/pr-snapshots
Browse files Browse the repository at this point in the history
Create snapshot versions with changes in PRs
  • Loading branch information
alejandrohdezma authored Dec 16, 2022
2 parents 9525fac + 8b858c7 commit 71853af
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 8 deletions.
15 changes: 8 additions & 7 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: monthly
time: "07:00"
timezone: Europe/Madrid
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: npm
directory: "/"
schedule:
interval: monthly
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run `npm run all` in the project
name: CI

on: [pull_request]

Expand All @@ -18,3 +18,12 @@ jobs:

- name: Run `npm run all`
run: npm run all

- name: Save PR number to `dist`
run: echo ${{ github.event.number }} > ./dist/PR_NUMBER

- name: Upload artifact with `dist` folder
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1
with:
name: dist
path: dist/
File renamed without changes.
79 changes: 79 additions & 0 deletions .github/workflows/release_pr_snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release a snapshot artifact for a PR

on:
pull_request_target:
types:
- closed
workflow_run:
workflows: ["CI"]
types:
- completed

jobs:
release-snapshot-artifact:
runs-on: ubuntu-latest
if: >
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout project
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0

- name: Download dist folder
uses: dawidd6/action-download-artifact@e6e25ac3a2b93187502a8be1ef9e9603afc34925 # v2.24.2
with:
run_id: ${{github.event.workflow_run.id }}
name: dist
path: dist

- name: Remove `dist` from `.gitignore`
run: sed -i -E 's|^/?dist/?||g' .gitignore

- name: Extract PR number
id: extract-pr-number
run: |
pr_number=$(cat ./dist/PR_NUMBER)
echo "PR_NUMBER=$pr_number" >> $GITHUB_OUTPUT
- name: Create snapshot branch
uses: alejandrohdezma/actions/commit-and-push@v1
with:
message: "Release snapshot for #${{ steps.extract-pr-number.outputs.PR_NUMBER }}"
force-push: "true"
branch: snapshots/${{ steps.extract-pr-number.outputs.PR_NUMBER }}

- name: Find Comment
uses: peter-evans/find-comment@f4499a714d59013c74a08789b48abe4b704364a0 # v2.1.0
id: find-comment
with:
issue-number: ${{ steps.extract-pr-number.outputs.PR_NUMBER }}
comment-author: "github-actions[bot]"
body-includes: A snapshot release

- name: Create comment
uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808 # v2.1.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.extract-pr-number.outputs.PR_NUMBER }}
edit-mode: replace
body: |
A snapshot release has been created as `snapshots/${{ steps.extract-pr-number.outputs.PR_NUMBER }}`.
You can test it out with:
```yaml
uses: scala-steward-org/scala-steward-action@snapshots/${{ steps.extract-pr-number.outputs.PR_NUMBER }}
```
It will be automatically recreated on any change to this PR.
delete-pr-branch:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target'
steps:
- name: Checkout project
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0

- name: Remove snapshot branch
run: git push origin -d snapshots/${{ github.event.number }} &>/dev/null

0 comments on commit 71853af

Please sign in to comment.