|
1 | | -name: GitHub Actions Demo |
| 1 | +name: Release |
2 | 2 | run-name: New Release Workflow |
3 | 3 | on: |
4 | 4 | workflow_dispatch: |
5 | 5 | inputs: |
6 | 6 | version: |
7 | | - description: 'Version number for the new release' |
| 7 | + description: "Version (for example 1.2.3)" |
8 | 8 | required: true |
9 | | - default: '2.0.0' |
10 | | - commit_hash: |
11 | | - description: 'Commit hash for the release' |
12 | | - required: true |
13 | | - default: '' |
14 | | - message: |
15 | | - description: 'Release message' |
16 | | - required: true |
17 | | - default: '' |
| 9 | + type: string |
18 | 10 | jobs: |
19 | | - run-test: |
| 11 | + validate-input: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Validate version |
| 16 | + shell: bash |
| 17 | + run: | |
| 18 | + VERSION="${{ inputs.version }}" |
| 19 | + |
| 20 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then |
| 21 | + echo "Invalid version: $VERSION" |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + |
| 25 | + echo "Version is valid: $VERSION" |
| 26 | + |
| 27 | + |
| 28 | + build: |
20 | 29 | runs-on: ubuntu-latest |
| 30 | + needs: validate-input |
| 31 | + |
21 | 32 | steps: |
22 | | - - name: Checkout code |
| 33 | + - name: Checkout main |
23 | 34 | uses: actions/checkout@v4 |
24 | 35 | with: |
25 | | - ref: ${{ github.event.inputs.commit_hash || github.sha }} |
26 | | - |
27 | | - - name: Run Tests |
28 | | - run: mvn test |
| 36 | + ref: main |
29 | 37 |
|
| 38 | + - name: Setup Java |
| 39 | + uses: actions/setup-java@v5 |
| 40 | + with: |
| 41 | + distribution: temurin |
| 42 | + java-version: 21 |
| 43 | + cache: maven |
30 | 44 |
|
31 | | - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." |
32 | | - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" |
33 | | - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." |
34 | | - - name: Check out repository code |
35 | | - uses: actions/checkout@v4 |
36 | | - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." |
37 | | - - run: echo "🖥️ The workflow is now ready to test your code on the runner." |
38 | | - - name: List files in the repository |
| 45 | + - name: Show build info |
39 | 46 | run: | |
40 | | - ls ${{ github.workspace }} |
41 | | - - run: echo "🍏 This job's status is ${{ job.status }}." |
| 47 | + echo "Building version ${{ inputs.version }}" |
| 48 | + git log -1 --oneline |
| 49 | +
|
| 50 | + - name: Build Maven project |
| 51 | + run: mvn -B clean verify |
0 commit comments