Skip to content

Commit

Permalink
feat: update github workflows to allow reuse the build workflow (#36)
Browse files Browse the repository at this point in the history
* feat: update github workflows to allow reuse the build workflow
* fix: fix condition to run cache related steps

Signed-off-by: Denis Golovin <dgolovin@redhat.com>
  • Loading branch information
dgolovin authored Feb 13, 2024
1 parent a67d1b8 commit f828ee4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 175 deletions.
52 changes: 45 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
runs-on:
required: true
type: string
ext-version:
required: false
type: string
default: latest
registry:
required: false
type: string

jobs:
build:
Expand All @@ -21,22 +28,53 @@ jobs:
with:
node-version: 18

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
- name: Get yarn cache directory path (Windows)
if: ${{ inputs.runs-on == 'windows-2022' }}
id: yarn-cache-dir-path-windows
run: echo "dir=$(yarn cache dir)" >> ${env:GITHUB_OUTPUT}

- name: Get yarn cache directory path (mac/Linux)
if: ${{ inputs.runs-on == 'ubuntu-22.04' || inputs.runs-on == 'macos-14' }}
id: yarn-cache-dir-path-unix
run: echo "dir=$(yarn cache dir)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v4
if: ${{ inputs.runs-on == 'windows-2022' }}
id: yarn-cache-windows
with:
path: ${{ steps.yarn-cache-dir-path-windows.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions/cache@v3
id: yarn-cache
- uses: actions/cache@v4
if: ${{ inputs.runs-on == 'ubuntu-22.04' || inputs.runs-on == 'macos-14' }}
id: yarn-cache-unix
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
path: ${{ steps.yarn-cache-dir-path-unix.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn
- name: Install dependencies (no cache found)
run: |
yarn --frozen-lockfile --network-timeout 180000
- name: Run Build
timeout-minutes: 20
run: yarn build

- name: Login to quay.io
if: ${{ inputs.registry == 'quay' }}
run: podman login --username ${{ secrets.QUAY_ROBOT_NAME }} --password ${{ secrets.QUAY_ROBOT_TOKEN }} quay.io

- name: Login to ghcr.io
if: ${{ inputs.registry == 'ghrc' }}
run: podman login --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} ghcr.io

- name: Build and Push Image
if: ${{ inputs.registry == 'ghrc' || inputs.registry == 'quay'}}
id: build-image
run: |
podman build -t quay.io/redhat-developer/podman-desktop-redhat-account-ext:${{ inputs.ext-version }} .
podman push quay.io/redhat-developer/podman-desktop-redhat-account-ext:${{ inputs.ext-version }}
39 changes: 4 additions & 35 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(npx yarn cache dir)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Execute yarn
if: ${{ steps.cacheNodeModules.outputs.cache-hit != 'true' }}
run: npx yarn --frozen-lockfile --network-timeout 180000

- name: Run Build
run: npx yarn build

- name: Login to ghcr.io
run: podman login --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} ghcr.io

- name: Build Image
id: build-image
run: |
podman build -t ghcr.io/${{ github.repository_owner }}/podman-desktop-redhat-account-ext:latest .
podman push ghcr.io/${{ github.repository_owner }}/podman-desktop-redhat-account-ext:latest
uses: redhat-developer/podman-desktop-redhat-account-ext/.github/workflows/build.yaml@main
with:
runs-on: ubuntu-latest
registry: 'ghrc'
101 changes: 7 additions & 94 deletions .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,97 +20,10 @@ name: pr-check
on: [pull_request]

jobs:
windows:
name: Windows
runs-on: windows-2022
timeout-minutes: 60
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> ${env:GITHUB_OUTPUT}

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn
run: |
yarn --frozen-lockfile --network-timeout 180000
- name: Run Build
timeout-minutes: 20
run: yarn build

darwin:
name: macOS
runs-on: macos-11
timeout-minutes: 40
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Execute yarn
if: ${{ steps.cacheNodeModules.outputs.cache-hit != 'true' }}
run: yarn --frozen-lockfile --network-timeout 180000

- name: Run Build
timeout-minutes: 20
run: yarn build

linux:
name: Linux
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Execute yarn
run: yarn --frozen-lockfile

- name: Run Build
timeout-minutes: 20
run: yarn build

pr-check-job:
strategy:
matrix:
target: [windows-2022, macos-14, ubuntu-20.04]
uses: redhat-developer/podman-desktop-redhat-account-ext/.github/workflows/build.yaml@main
with:
runs-on: ${{ matrix.target }}
48 changes: 9 additions & 39 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

- name: Generate tag utilities
id: TAG_UTIL
run: |
Expand All @@ -64,6 +65,7 @@ jobs:
echo "Tagging with ${{ steps.TAG_UTIL.outputs.githubTag }}"
git tag ${{ steps.TAG_UTIL.outputs.githubTag }}
git push origin ${{ steps.TAG_UTIL.outputs.githubTag }}
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
Expand All @@ -77,56 +79,24 @@ jobs:

build:
needs: [tag]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(npx yarn cache dir)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Execute yarn
if: ${{ steps.cacheNodeModules.outputs.cache-hit != 'true' }}
run: npx yarn --frozen-lockfile --network-timeout 180000

- name: Run Build
run: npx yarn build

- name: Login to quay.io
run: podman login --username ${{ secrets.QUAY_ROBOT_NAME }} --password ${{ secrets.QUAY_ROBOT_TOKEN }} quay.io

- name: Build Image
id: build-image
run: |
podman build -t quay.io/redhat-developer/podman-desktop-redhat-account-ext:${{ needs.tag.outputs.extVersion }} .
podman push quay.io/redhat-developer/podman-desktop-redhat-account-ext:${{ needs.tag.outputs.extVersion }}
uses: redhat-developer/podman-desktop-redhat-account-ext/.github/workflows/build.yaml@main
with:
runs-on: ubuntu-latest
registry: quay
ext-version: ${{ needs.tag.outputs.extVersion }}

release:
needs: [tag, build]
name: Release
runs-on: ubuntu-20.04
steps:
- name: id
run: echo the release id is ${{ needs.tag.outputs.releaseId}}
run: echo the release id is ${{ needs.tag.outputs.releaseId }}

- name: Publish release
uses: StuYarrow/publish-release@v1.1.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
id: ${{ needs.tag.outputs.releaseId}}
id: ${{ needs.tag.outputs.releaseId }}

0 comments on commit f828ee4

Please sign in to comment.