-
Notifications
You must be signed in to change notification settings - Fork 14
134 lines (130 loc) · 5.35 KB
/
release.yml
File metadata and controls
134 lines (130 loc) · 5.35 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Release Every Monday
on:
workflow_dispatch:
schedule:
# At 10AM EST Monday
- cron: '0 15 * * 1'
# Sets the GITHUB_TOKEN permissions to allow release
permissions:
contents: write
id-token: write # Required for OIDC connection with NPM
# This action requires a GitHub app with content write access installed
# to bypass the main branch protection rule and dispatch the event to a different repo
jobs:
release:
runs-on: ubuntu-latest
outputs:
no_commit: ${{ steps.git-release.outputs.NO_COMMIT }}
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PEM }}
owner: ${{ github.repository_owner }}
repositories: |
veda-ui
veda-config
next-veda-ui
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
- name: git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Use Node.js ${{ env.NODE }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE }}
registry-url: https://registry.npmjs.org/
- run: yarn
# Clean up any stale version tags left from failed release runs.
# Context:
# - Each release run uses release-it to bump package.json, create a new Git tag (e.g., v7.0.0),
# and then publish to NPM. If the run fails after the tag is created but before publish,
# that tag remains both locally in the local repo (inside the GitHub Actions runner) and remotely on GitHub.
# - "Locally" refers to the temporary clone created by actions/checkout@v4 inside the workflow runner.
# - "Remotely" refers to the GitHub repository itself ("origin" on GitHub.com).
# The command `git push origin :refs/tags/v7.0.0` deletes the remote tag.
# - On the next run, if that stale tag still exists, release-it detects no version change
# and fails with “Version not changed”.
# This step checks whether the tag for the current package.json version already exists,
# and deletes it locally and remotely so release-it can safely recreate it during this run.
- name: Clean stale tags from failed releases
run: |
LAST_TAG=$(git describe --tags --abbrev=0 || echo "")
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$LAST_TAG" = "v$CURRENT_VERSION" ]; then
echo "Skipping cleanup: tag v$CURRENT_VERSION already valid."
else
STALE_TAG="v$CURRENT_VERSION"
if git rev-parse "$STALE_TAG" >/dev/null 2>&1; then
echo "Removing stale tag $STALE_TAG"
git tag -d "$STALE_TAG" || true
git push origin ":refs/tags/$STALE_TAG" || true
fi
fi
- name: Release through Git
id: git-release
run: yarn release --ci --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Version Variable
id: set-version
run: echo "VERSION=$(npm pkg get version)" >> $GITHUB_ENV
- name: Publish package to NPM
run: |
yarn buildlib
npm publish
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{steps.generate-token.outputs.token}}
repository: nasa-impact/veda-config
event-type: update-version
client-payload: '{"ref": "${{ github.ref }}", "VERSION_NUMBER": "${{ steps.git-release.outputs.VERSION_NUMBER }}"}'
notify:
# If any of job fails
if: failure()
runs-on: ubuntu-latest
needs:
- release
steps:
- name: Notify failure through Slack
if: needs.release.outputs.no_commit != 'true'
uses: slackapi/slack-github-action@v2.0.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "*VEDA UI Release failed*: "
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "*VEDA UI Release failed*: Check action page to see the details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Notify no commit through Slack
if: needs.release.outputs.no_commit == 'true'
uses: slackapi/slack-github-action@v2.0.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "*VEDA UI Release skipped*: "
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "VEDA UI release was skipped as there are no commits after the last release: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"