Skip to content

Commit 38e80c0

Browse files
fix:(ci): adjust configuration of subworkflows (#1597)
* fix:(ci): workflows that depends on another workflow * chore(ci): use env variable to avoid unexpected substitution behavior
1 parent eeea28d commit 38e80c0

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

.github/workflows/check.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ jobs:
2626
fetch-depth: 0
2727

2828
- name: Check Git tag format
29+
env:
30+
TYPE_GRAPHQL_REF_NAME: ${{ github.ref_name }}
2931
run: |
30-
_tag="${{ github.ref_name }}"
32+
_tag="$TYPE_GRAPHQL_REF_NAME"
3133
if ! printf "%s\n" "$_tag" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$'; then
3234
printf '[ERROR]: Git tag (%s) wrong format\n' "$_tag"
3335
exit 1
@@ -49,14 +51,18 @@ jobs:
4951

5052
- name: Remove leading v* from GitHub version
5153
id: version_github
54+
env:
55+
TYPE_GRAPHQL_VERSION: ${{ steps.version_v_github.outputs.release }}
5256
run: |
53-
_version="${{ steps.version_v_github.outputs.release }}"
57+
_version="$TYPE_GRAPHQL_VERSION"
5458
printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT"
5559
5660
- name: Read Git tag version
5761
id: version_gittag
62+
env:
63+
TYPE_GRAPHQL_REF_NAME: ${{ github.ref_name }}
5864
run: |
59-
_version="${{ github.ref_name }}"
65+
_version="$TYPE_GRAPHQL_REF_NAME"
6066
printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT"
6167
6268
- name: Compare package.json with Git tag
@@ -76,16 +82,24 @@ jobs:
7682
lenient: false
7783

7884
- name: Check package.json == Git tag
85+
env:
86+
TYPE_GRAPHQL_COMPARISON: ${{ steps.comparison_package_gittag.outputs.comparison-result }}
87+
TYPE_GRAPHQL_VERSION_PACKAGE: ${{ steps.version_package.outputs.value }}
88+
TYPE_GRAPHQL_VERSION_TAG: ${{ steps.version_gittag.outputs.value }}
7989
run: |
80-
if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then
81-
printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}"
90+
if [ ! "$TYPE_GRAPHQL_COMPARISON" = "=" ]; then
91+
printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "$TYPE_GRAPHQL_VERSION_PACKAGE" "$TYPE_GRAPHQL_VERSION_TAG"
8292
exit 1
8393
fi
8494
8595
- name: Check Git tag > GitHub
96+
env:
97+
TYPE_GRAPHQL_COMPARISON: ${{ steps.comparison_gittag_github.outputs.comparison-result }}
98+
TYPE_GRAPHQL_VERSION_TAG: ${{ steps.version_gittag.outputs.value }}
99+
TYPE_GRAPHQL_VERSION_GITHUB: ${{ steps.version_github.outputs.value }}
86100
run: |
87-
if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then
88-
printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}"
101+
if [ ! "$TYPE_GRAPHQL_COMPARISON" = ">" ]; then
102+
printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "$TYPE_GRAPHQL_VERSION_TAG" "$TYPE_GRAPHQL_VERSION_GITHUB"
89103
exit 1
90104
fi
91105

.github/workflows/license.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
schedule:
55
- cron: "0 0 1 1 *"
66

7+
concurrency:
8+
group: ${{ github.workflow }}
9+
cancel-in-progress: true
10+
711
jobs:
812
license:
913
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,55 @@ on:
1010
- master
1111

1212
concurrency:
13-
group: ${{ github.workflow }}-${{ github.ref }}
13+
group: ${{ github.workflow }}
1414
cancel-in-progress: true
1515

1616
jobs:
1717
release:
1818
name: Release package on NPM
1919
runs-on: ubuntu-latest
20-
if: github.event.workflow_run.conclusion == 'success' && startsWith(github.ref_name, 'v')
20+
if: github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'refs/tags/v')
2121
permissions:
2222
contents: write
2323
id-token: write
2424
steps:
2525
- name: Checkout
2626
uses: actions/checkout@v4
27+
with:
28+
ref: ${{ github.event.workflow_run.head_branch }}
2729

2830
- name: Read package.json version
2931
uses: sergeysova/jq-action@v2
3032
id: version
3133
with:
3234
cmd: jq --raw-output .version package.json
3335

36+
- name: Read Git tag version
37+
id: tag
38+
env:
39+
TYPE_GRAPHQL_REF: ${{ github.event.workflow_run.head_branch }}
40+
run: |
41+
_ref="$TYPE_GRAPHQL_REF"
42+
printf 'value=%s\n' "${_ref#refs/tags/}" >> "$GITHUB_OUTPUT"
43+
44+
- name: Check package.json == Git tag
45+
env:
46+
TYPE_GRAPHQL_VERSION_PACKAGE: ${{ steps.version.outputs.value }}
47+
TYPE_GRAPHQL_VERSION_TAG: ${{ steps.tag.outputs.value }}
48+
run: |
49+
_version="v$TYPE_GRAPHQL_VERSION_PACKAGE"
50+
if [ ! "$_version" = "$TYPE_GRAPHQL_VERSION_TAG" ]; then
51+
printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "$_version" "$TYPE_GRAPHQL_VERSION_TAG"
52+
exit 1
53+
fi
54+
3455
- name: Determine if version is prerelease
3556
id: prerelease
57+
env:
58+
TYPE_GRAPHQL_VERSION: ${{ steps.version.outputs.value }}
3659
run: |
3760
_prerelease=
38-
if printf "%s\n" "${{ steps.version.outputs.value }}" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then
61+
if printf "%s\n" "$TYPE_GRAPHQL_VERSION" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then
3962
_prerelease=false
4063
else
4164
_prerelease=true
@@ -61,7 +84,7 @@ jobs:
6184
run: |
6285
npm run prepublishOnly
6386
env:
64-
TYPE_GRAPHQL_REF: ${{ github.ref_name }}
87+
TYPE_GRAPHQL_REF: ${{ steps.tag.outputs.value }}
6588

6689
- name: Build Changelog
6790
id: changelog
@@ -79,14 +102,15 @@ jobs:
79102
prerelease: ${{ steps.prerelease.outputs.value == 'true' }}
80103

81104
- name: Publish
105+
env:
106+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
107+
TYPE_GRAPHQL_PRERELEASE: ${{ steps.prerelease.outputs.value }}
82108
run: |
83109
_tag=
84-
if [ "${{ steps.prerelease.outputs.value }}" = "true" ]; then
110+
if [ "$TYPE_GRAPHQL_PRERELEASE" = "true" ]; then
85111
_tag="next"
86112
else
87113
_tag="latest"
88114
fi
89115
90116
npm publish --ignore-scripts --tag "$_tag"
91-
env:
92-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/website.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- master
1111

1212
concurrency:
13-
group: ${{ github.workflow }}-${{ github.ref }}
13+
group: ${{ github.workflow }}
1414
cancel-in-progress: true
1515

1616
jobs:
@@ -22,6 +22,7 @@ jobs:
2222
- name: Checkout
2323
uses: actions/checkout@v4
2424
with:
25+
ref: ${{ github.event.workflow_run.head_branch }}
2526
fetch-depth: 0
2627

2728
- name: Setup Node.js
@@ -46,4 +47,4 @@ jobs:
4647
user_name: "github-actions[bot]"
4748
user_email: "github-actions[bot]@users.noreply.github.com"
4849
full_commit_message: |
49-
Deploy website based on ${{ github.sha }}
50+
Deploy website based on ${{ github.event.workflow_run.head_sha }}

0 commit comments

Comments
 (0)