Skip to content

Commit

Permalink
Merge pull request #131 from Geoportail-Luxembourg/GSLUX-635_automate…
Browse files Browse the repository at this point in the history
…_tag_on_merge

trigger auto tag on PR edit and merge
  • Loading branch information
mki-c2c authored Aug 12, 2024
2 parents 20128c2 + e6acfa6 commit 34816b0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
47 changes: 42 additions & 5 deletions .github/workflows/ci_bundle.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
name: CI_package
on:
push:
branches:
- 'main'
tags:
- '*'
jobs:
tag-version:
if: github.ref_type != 'tag'
runs-on: ubuntu-latest
steps:
- name: checkout ${{ github.head_ref }}
uses: actions/checkout@v4
with:
# default depth is 1, but we need the parent refs
fetch-depth: 2
- name: compute tag name
shell: bash
run: |
branch=$([[ $(git log --pretty="%p" -n 1 | wc -w) -gt 1 ]] \
&& echo $(git log -n 1 --pretty="%s" | sed "s|.*Geoportail-Luxembourg/\(.*\)|\1|") \
|| git branch --show-current)
echo $branch
echo "AUTO_TAG=${branch}_CI_$(git log -n 1 --pretty=%h)" >> $GITHUB_ENV
- name: tag ${{ github.head_ref }}
run: |
git tag ${{ env.AUTO_TAG }}
git push --tags
lux-package:
# the combination (if always) + (needs tag-version) makes sure the lux-package job runs
# after completion of the tag-version job.
# In case of a tag push, the tag-version job is skipped but the lux-package job will run
# In case of a closed PR, the tag-version job runs first, the lux-package job runs after completion
if: ${{ always() }}
needs: tag-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 2
- name: compute tag name
shell: bash
run: |
branch=$([[ $(git log --pretty="%p" -n 1 | wc -w) -gt 1 ]] \
&& echo $(git log -n 1 --pretty="%s" | sed "s|.*Geoportail-Luxembourg/\(.*\)|\1|") \
|| git branch --show-current)
echo $branch
echo "AUTO_TAG=${branch}_CI_$(git log -n 1 --pretty=%h)" >> $GITHUB_ENV
- name: create release
id: create_release
uses: octokit/[email protected]
Expand All @@ -16,11 +57,7 @@ jobs:
route: POST /repos/{owner}/{repo}/releases
owner: 'Geoportail-Luxembourg'
repo: 'luxembourg-geoportail'
tag_name: ${{ github.ref }}
- uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
tag_name: ${{ github.ref_type == 'tag' && github.ref || env.AUTO_TAG }}
- uses: actions/setup-node@v3
with:
node-version: 16
Expand Down
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ The results of the build can be found in the folder `bundle`

An automatic mecanism has been created with github actions. This workflow is triggered when a tag is pushed into the repo.

For the moment there is no automatic tag generation on pull requests, so for dev, the following naming conventions are recommended:
<branch_name>\_tag\_<short_commit>
For dev releases, create a new tag, the CI will then generate the release. The following naming conventions are recommended:
<branch_name>\_DEV\_<short_commit>

an npm script is included in package.json, so just call

```
echo $(git rev-parse --abbrev-ref HEAD)_tag_$(git rev-parse --short HEAD)
npm run tag
git push --tags
```

The CI automatically builds the lib, creates a release named after the tag and includes the built bundle in the release. The built package can then be downloaded at the URL:
Expand All @@ -112,6 +115,41 @@ The CI automatically builds the lib, creates a release named after the tag and i

This package URL can also be used to reference the dependency for NPM in package.json, see below

### Automatic tag in CI

On merge of a PR on main branch the CI will create an automatic tag of type
<branch_name>\_CI\_<short_commit>

### Cleanup of tags:

Everyone should clean their own dev-only tags.

The following scripts might come handy to avoid messing up the repo with unused tags.

#### cleaning out local tags before pushing any

Before a git push --tags, one should sync the local tags with the remote ones:

```
for t in $(git tag -l); do git tag -d $t; done
git fetch -t
```

#### cleaning usused tags

There is not any CI automation yet for cleaning tags. However, the naming convention (dev tags shall start with the branch name) makes cleaning them much easier.

```
for t in $(git tag -l | grep GSLUX-635_automate_tag_on_merge_); do git push origin :refs/tags/$t; done
for t in $(git tag -l | grep GSLUX-635_automate_tag_on_merge_); do git tag -d $t; done
```

where `GSLUX-635_automate_tag_on_merge` is the branch name

#### cleaning releases

Releases must be deleted manually in the github web interface. The github API might be used, but this would be some extra complexity for the moment.

### Import the lib in another app

You can include the built lib multiple ways in the `package.json`:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0-dev",
"private": true,
"scripts": {
"tag": "git tag $(git rev-parse --abbrev-ref HEAD)_DEV_$(git rev-parse --short HEAD)",
"start": "npm run dev",
"dev": "vite --force",
"build": "run-p type-check build-only",
Expand Down

0 comments on commit 34816b0

Please sign in to comment.