Skip to content

Commit

Permalink
Upgrade CI/CD workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
socheatsok78 committed May 2, 2024
1 parent 9f7ce1e commit 02137bd
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 36 deletions.
43 changes: 7 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,22 @@
name: Docker Image
name: Build

on:
workflow_dispatch:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened]
# schedule:
# # Runs at 15:00, only on Saturday.
# - cron: '0 15 * * SAT'
workflow_call:
inputs:
version:
type: string
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: releases
uses: actions-matrix/github-release-matrix-action@v1
with:
repository: "hashicorp/vault"
limit: 10
env:
GH_TOKEN: ${{ github.token }}
- id: filtered
run: |
cat "$GITHUB_RELEASE_MATRIX_ACTION_RELEASE_FILE" |\
jq -r ".[] | select(.tag_name | contains(\"ent\") | not) | ." |\
jq -rs ". | tostring" > releases.json
echo "matrix={\"releases\": $(cat "releases.json")}" | tee -a "$GITHUB_OUTPUT"
shell: bash
outputs:
matrix: ${{ steps.filtered.outputs.matrix }}

build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: generate
strategy:
matrix: ${{ fromJson(needs.generate.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -70,7 +41,7 @@ jobs:
images: ghcr.io/${{ github.repository }}
flavor: latest=false
tags: |
type=semver,pattern={{version}},value=${{ matrix.releases.tag_name }}
type=semver,pattern={{version}},value=${{ inputs.version }}
- name: Generate GitHub metadata
id: github-meta
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Docker Image

on:
workflow_dispatch:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened]
# schedule:
# # Runs at 15:00, only on Saturday.
# - cron: '0 15 * * SAT'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
generate:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.filtered.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- id: releases
uses: actions-matrix/github-release-matrix-action@v1
with:
repository: "hashicorp/vault"
limit: 10
env:
GH_TOKEN: ${{ github.token }}
- id: filtered
run: |
cat "$GITHUB_RELEASE_MATRIX_ACTION_RELEASE_FILE" |
jq -r ".[] | select(.tag_name | contains(\"ent\") | not) | ." |
jq -rs ". | tostring" > releases.json
echo "matrix={\"releases\": $(cat "releases.json")}" | tee -a "$GITHUB_OUTPUT"
shell: bash

generate-canonical:
runs-on: ubuntu-latest
needs: generate
outputs:
matrix: ${{ steps.filtered.outputs.matrix }}
steps:
- id: filtered
run: |
echo '${{ needs.generate.outputs.matrix }}' |
jq ".[] | select(.tag_name | contains(\"ent\") | not) | .tag_name" |
jq "split(\".\") | del(.[-1]) | join(\".\")" |
jq "ltrimstr(\"v\")" |
jq -rs ". | unique | sort | tostring" \
> releases.json
echo "matrix={\"releases\": $(cat "releases.json")}" | tee -a "$GITHUB_OUTPUT"
shell: bash

canonical:
uses: .github/workflows/build.yml
needs: generate-canonical
strategy:
matrix: ${{fromJson(needs.generate-canonical.outputs.matrix)}}
with:
version: ${{ matrix.releases }}

versioned:
uses: .github/workflows/build.yml
needs: generate
strategy:
matrix: ${{fromJson(needs.generate.outputs.matrix)}}
with:
version: ${{ matrix.releases.tag_name }}

0 comments on commit 02137bd

Please sign in to comment.