Skip to content

Commit

Permalink
Refactor GitHub Actions workflows
Browse files Browse the repository at this point in the history
-  Remove unnecessary lines in deploy.yml
-  Rename `validate-pr` job to `validate-labels` in pr_lint.yml and add concurrency settings
-  Modify the way of getting pull request data in pr_lint.yml
-  Add `validate-code`, `validate-docker-build`, and `validate-branch` jobs in pr_lint.yml with proper concurrency settings
-  In `validate-docker-build`, implement Docker image building and caching
-  Check branch name with version in `validate-branch` job
  • Loading branch information
jag-k committed Apr 9, 2024
1 parent 63d7214 commit e0fc01a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ jobs:
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7


release:
runs-on: ubuntu-latest
if: ${{ needs.lint.outputs.is_release }}
Expand Down Expand Up @@ -141,7 +140,6 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v1

with:
body: |
Docker image: [`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.version }}`](https://github.com/jag-k/owntinfoil/pkgs/container/owntinfoil/${{ steps.docker_build.outputs }}?tag=${{ steps.get_version.outputs.version }})
Expand Down
52 changes: 47 additions & 5 deletions .github/workflows/pr_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ on:
pull_request:

jobs:
validate-pr:
validate-labels:
runs-on: ubuntu-latest
concurrency:
group: validate-pr
cancel-in-progress: true
steps:
- name: Check labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
Expand All @@ -37,7 +42,9 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
Expand All @@ -53,7 +60,9 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
Expand All @@ -65,6 +74,9 @@ jobs:
validate-code:
runs-on: ubuntu-latest
concurrency:
group: validate-pr
cancel-in-progress: true
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
Expand Down Expand Up @@ -92,11 +104,41 @@ jobs:
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
validate-docker-build:
runs-on: ubuntu-latest
needs: validate-code
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: user/app:pr-${{ github.event.pull_request.number }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: linux/amd64,linux/arm64,linux/arm/v7

validate-branch:
runs-on: ubuntu-latest
needs:
- validate-code

concurrency:
group: validate-pr
cancel-in-progress: true
if: startsWith(github.head_ref, 'release/')
steps:
- name: Check branch name with version
Expand Down

0 comments on commit e0fc01a

Please sign in to comment.