-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (103 loc) · 4.7 KB
/
Version-Check.yml
File metadata and controls
116 lines (103 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Package.json Version Check
description: Check the package.json version for a new version or same version
on:
workflow_call:
inputs:
cancel-on-same:
description: Cancel the running workflow and stop the whole workflow from running if the versions are the same
required: false
default: false
type: boolean
project-name:
description: The name of the project (default is the repo owner + the repo name)
required: false
default: '@${{ github.repository }}'
type: string
repository-owner:
description: The repository owner (default `bracketed`, can be customised)
required: false
default: bracketed
type: string
operating-system:
description: Base OS to use (default `ubuntu-latest`)
required: false
default: ubuntu-latest
type: string
with-submodules:
description: Whether to include submodules when checking out the repository (default `true`)
required: false
default: true
type: boolean
working-directory:
description: The working directory to run the commands in
required: false
default: .
type: string
checkout-depth:
description: The depth of `actions/checkout` to fetch from (default `0`)
required: false
default: 0
type: number
checkout-ref:
description: The branch reference `actions/checkout` will use to pull from (default is the same branch the workflow is running on)
required: false
default: ${{ github.ref }}
type: string
secrets:
BRSFTWORKS_TOKEN:
description: The token to authenticate with the GitHub repository used to bypass `main` branch checks
required: true
concurrency:
group: ${{ github.workflow }}|${{ github.head_ref || github.ref }}|${{ inputs.working-directory }}|${{ inputs.operating-system }}|${{ inputs.project-name }}|${{ inputs.checkout-depth }}|${{ inputs.checkout-ref }}|${{ inputs.cancel-on-same }}
cancel-in-progress: true
jobs:
check:
name: Check version for ${{ inputs.project-name }}
runs-on: ${{ inputs.operating-system }}
if: github.repository_owner == ${{ inputs.repository-owner }}
outputs:
result: ${{ steps.version-check.outputs.result }}
version: ${{ steps.version-check.outputs.version }}
steps:
- name: Checkout Project
uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.checkout-depth }}
ref: ${{ inputs.checkout-ref }}
token: ${{ secrets.BRSFTWORKS_TOKEN }}
submodules: ${{ inputs.with-submodules }}
- name: Configure Git
uses: Bracketed/Workflows/actions/git-configure@main
with:
GITHUB_TOKEN: ${{ secrets.BRSFTWORKS_TOKEN }}
- name: Check for version change
id: version-check
run: |
if [ ! -f package.json ]; then
echo "package.json not found."
echo "result=null" >> "$GITHUB_OUTPUT"
echo "version=null" >> "$GITHUB_OUTPUT"
exit 0
fi
OLD_VERSION=$(git show HEAD~1:package.json | jq -r .version)
NEW_VERSION=$(jq -r .version package.json)
echo "Old Version: $OLD_VERSION"
echo "Current/New Version: $NEW_VERSION"
if [ "$OLD_VERSION" == "$NEW_VERSION" ]; then
echo "Version has not changed. Exiting..."
echo "result=same" >> "$GITHUB_OUTPUT"
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Version has changed! Exiting..."
echo "New Version: $NEW_VERSION"
echo "result=different" >> "$GITHUB_OUTPUT"
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
cancel:
needs: [check]
if: ((inputs.cancel-on-same == true && needs.check.outputs.result == 'same') || needs.check.outputs.result == 'null')
uses: Bracketed/Workflows/.github/workflows/Workflow-Cancel.yml@main
name: Cancel workflows
permissions:
actions: write
secrets: inherit