-
Notifications
You must be signed in to change notification settings - Fork 4
143 lines (140 loc) · 5.03 KB
/
build.yml
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
135
136
137
138
139
140
141
142
143
# Run whenever code is pushed or when manually triggers from Github UI
on:
push:
workflow_dispatch:
inputs:
version:
description: '(Optional) Version name, in format v1.2.3'
required: false
name: Build & Release
jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-20.04
if: github.event_name == 'workflow_dispatch'
outputs:
version: ${{ steps.pkg.outputs.prop }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Configure git user & email
run: |
git config user.name Github Actions
git config user.email [email protected]
- name: Prepare new version
run: npx standard-version --release-as '${{ github.event.inputs.version }}'
- name: Commit changes
run: git push --follow-tags
- name: Get package version
id: pkg
uses: notiz-dev/github-action-json-property@release
with:
path: 'package.json'
prop_path: 'version'
create-release:
name: Create Release
# Run this job after prepare-release, whether or not it runs, and run on
# either a tag push or when manually triggered
if: always() && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')))
needs: prepare-release
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
upload_url: ${{ steps.release.outputs.upload_url }}
runs-on: ubuntu-20.04
steps:
- name: Get tag name
id: get_tag
run: |
if [[ -n '${{ needs.prepare-release.outputs.version }}' ]]; then
TAG=v${{ needs.prepare-release.outputs.version }}
else
# Use bash parameter expansion to remove refs/tags/ from GITHUB_REF
TAG=${GITHUB_REF/refs\/tags\//}
fi
echo ::set-output name=tag::$TAG
- name: Create Release
id: release
uses: actions/create-release@v1
continue-on-error: true # Ignore failure if release already exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.get_tag.outputs.tag }}
release_name: Release ${{ steps.get_tag.outputs.tag }}
body: |
For changes see [CHANGELOG.md](CHANGELOG.md)
draft: false
prerelease: false
build:
# This step runs on every push, ensures there is an artifact for each push
name: Build
runs-on: ubuntu-20.04
if: always()
needs: [prepare-release, create-release]
outputs:
artifact: ${{ steps.filename.outputs.filename }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get version
id: version
run: |
# Use either the git tag or the git commit sha to identify the version
if [[ -n '${{ needs.create-release.outputs.tag }}' ]]; then
VERSION=${{ needs.create-release.outputs.tag }}
else
# Get a short ID to the commit used to build this version
VERSION=$(git rev-parse --short ${{ github.sha }})
fi
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Write version to metadata.json
uses: jossef/[email protected]
with:
file: metadata.json
field: version
value: ${{ steps.version.outputs.VERSION }}
- name: Create filename
id: filename
run: echo "FILENAME=mapeo-default-config_${{ steps.version.outputs.VERSION }}.mapeoconfig" >> "$GITHUB_OUTPUT"
- run: npm ci
- name: Build asset
id: build_asset
run: |
mkdir -p build
npm exec mapeo-settings build -l 'en' -o build/${{ steps.filename.outputs.FILENAME }}
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.filename.outputs.FILENAME }}
path: build/${{ steps.filename.outputs.FILENAME }}
upload-release:
name: Upload release
runs-on: ubuntu-20.04
# Only runs if a release has been created
needs: [build, create-release]
steps:
- name: Download artifact
id: download
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact }}
- name: 'Echo download path'
run: echo ${{ steps.download.outputs.download-path }}
- name: Display structure of downloaded files
run: ls -R
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ needs.build.outputs.artifact }}
asset_name: ${{ needs.build.outputs.artifact }}
asset_content_type: application/zip