-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Implement gated automated PR building
Only checkout/build PR branches if labelled first
- Loading branch information
Showing
2 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
name: PR Workflow | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- labeled | ||
- synchronize | ||
- reopened | ||
- opened | ||
branches: | ||
- 'develop' | ||
|
||
jobs: | ||
test: | ||
name: Run Tests | ||
runs-on: ubuntu-latest | ||
if: contains(github.event.pull_request.labels.*.name, 'safe to test') | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.x' | ||
cache: 'npm' | ||
- name: Install dev dependencies | ||
run: npm ci | ||
- name: Build Backend | ||
run: 'npm run build:backend' | ||
- name: Test Backend | ||
run: npm run test | ||
|
||
release-snapshot: | ||
name: Release snapshot | ||
runs-on: ubuntu-latest | ||
needs: test | ||
if: contains(github.event.pull_request.labels.*.name, 'safe to test') | ||
permissions: | ||
packages: write | ||
contents: read | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- dockerfile: ./Dockerfile | ||
suffix: '' | ||
platforms: 'linux/amd64,linux/arm64' | ||
- dockerfile: ./debian.Dockerfile | ||
suffix: '-debian' | ||
platforms: 'linux/amd64,linux/arm64' | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
foxxmd/multi-scrobbler | ||
ghcr.io/foxxmd/multi-scrobbler | ||
tags: | | ||
type=ref,event=pr,suffix=${{ matrix.suffix }} | ||
flavor: | | ||
latest=false | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
env: | ||
APP_VERSION: ${{ format('pr{0}-{1}', github.event.number, github.event.pull_request.head.sha ) }} | ||
with: | ||
context: . | ||
push: true | ||
file: ${{ matrix.dockerfile }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
platforms: ${{ matrix.platforms }} | ||
build-args: | | ||
APP_BUILD_VERSION=${{env.APP_VERSION}} | ||
combine-and-comment: | ||
name: Leave comment | ||
runs-on: ubuntu-latest | ||
needs: release-snapshot | ||
if: contains(github.event.pull_request.labels.*.name, 'safe to test') | ||
steps: | ||
- name: Create comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
recreate: true | ||
header: "pr-release" | ||
message: | | ||
#### :package: A new release has been made for this pull request. | ||
To play around with this PR, pull an image: | ||
* `foxxmd/multi-scrobbler:pr-${{ github.event.number }}` | ||
* `foxxmd/multi-scrobbler:pr-${{ github.event.number }}-debian`. | ||
Images are available for x86_64 and ARM64. | ||
> Latest commit: ${{ github.event.pull_request.head.sha }} |
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