Skip to content

Commit

Permalink
Add CI (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm authored Aug 24, 2024
1 parent 40fc32c commit 9c9bcb0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 14 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'CI'

on: # Build any PRs and main branch changes
pull_request:
types:
- opened
- synchronize
push:
branches: [ master ]
schedule:
- cron: '0 0 1 * *' # Every month

concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
cancel-in-progress: true

jobs:
static-tests:
name: Static tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate action file syntax
run: yamllint -d relaxed action.yml
23 changes: 23 additions & 0 deletions .github/workflows/trigger-functional-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Trigger test repo workflow'
on:
workflow_run:
workflows: ["CI"]
types: [completed]

jobs:
tests:
name: Run functional tests
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Trigger test repository worfklow
env:
GITHUB_TOKEN: ${{ secrets.FUNCTIONAL_TESTS_TRIGGER }}
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/yoanm/gha-versioning-test-repo/actions/workflows/functional-tests.yml/dispatches \
-f "ref=master" \
-f "inputs[sha]=${{ github.event.workflow_run.head_sha }}"
44 changes: 30 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: gha-versioning
description: |
Create (or override existing) vX and vX.Y based on the provided tag. Useful to maintain GitHub Action tags up to date.
Create (or override existing) vX and vX.Y based on the provided tag.
Useful to maintain GitHub Action tags up to date.
branding:
icon: tag
color: yellow
Expand All @@ -17,7 +18,13 @@ inputs:
git-name:
description: The name for the GIT user creating the tags
required: false
default: 'github-actions'
default: 'github-actions[bot]'
working-directory:
description: |
Directory to the Git repository to tag.
Useful only if you checkout it in a specific location !
required: false
default: '${{ github.workspace }}'

outputs:
minor-tag:
Expand All @@ -30,10 +37,11 @@ outputs:
runs:
using: "composite"
steps:
# Even if an input is marked as "required", an empty value (or no value) may be passed !
# Even if an input is marked as "required", empty/no value may be passed !
- shell: bash
env:
FULL_TAG: ${{ inputs.tag }}
working-directory: ${{ inputs.working-directory }}
run: |
# Validate provided tag ...
if ! [[ "$FULL_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
Expand All @@ -45,21 +53,22 @@ runs:
shell: bash
env:
FULL_TAG: ${{ inputs.tag }}
working-directory: ${{ inputs.working-directory }}
run: |
# Generate vX and vX.Y tags
echo "Original tag -> $FULL_TAG"
MINOR_TAG=`echo $FULL_TAG | cut -d '.' -f 1-2`;
echo "Minor tag -> $MINOR_TAG"
if ! [[ "$MINOR_TAG" =~ ^v[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid minor tag format (expected vX.Y) !"
exit 2
fi;
echo "minor=$MINOR_TAG" >> "$GITHUB_OUTPUT"
MAJOR_TAG=`echo $FULL_TAG | cut -d '.' -f 1`;
echo "Major tag -> $MAJOR_TAG"
if ! [[ "$MAJOR_TAG" =~ ^v[0-9]$ ]]; then
if ! [[ "$MAJOR_TAG" =~ ^v[0-9]+$ ]]; then
echo "::error::Invalid major tag format (expected vX) !"
exit 3
fi;
Expand All @@ -72,13 +81,20 @@ runs:
MAJOR_TAG: ${{ steps.generate-tags.outputs.major }}
GIT_EMAIL: ${{ inputs.git-email }}
GIT_NAME: ${{ inputs.git-name }}
working-directory: ${{ inputs.working-directory }}
run: |
# Create & push tags
# /!\ Update the original tag at the end (and after 1s delay) so it will be the latest tag generated,
# otherwise, github releases won't take it automatically as latest tag to automatically generate the changelog !
git config --global user.email "$GIT_EMAIL" # Required when -m is used !
git config --global user.name "$GIT_NAME" # Required when -m is used !
git tag -f $MAJOR_TAG -m "Linked to $FULL_TAG tag" $FULL_TAG && \
git tag -f $MINOR_TAG -m "Linked to $FULL_TAG tag" $FULL_TAG && \
sleep 1 && git tag -f $FULL_TAG -m "See also $MAJOR_TAG or $MINOR_TAG tags" $FULL_TAG && \
git push origin --force $MINOR_TAG $MAJOR_TAG $FULL_TAG
# User email and name are required when -m is used !
(
git config --global user.email "$GIT_EMAIL" && \
git config --global user.name "$GIT_NAME" \
) || exit 1
# Update the original tag BUT keep the original message !
git tag -l --format='%(contents)' $FULL_TAG > ./TAG_MSG || exit 2
(git tag -f $MAJOR_TAG -m "Linked to $FULL_TAG tag" ${FULL_TAG}^{} && \
git tag -f $MINOR_TAG -m "Linked to $FULL_TAG tag" ${FULL_TAG}^{} && \
sleep 1 && git tag -f $FULL_TAG -F ./TAG_MSG ${FULL_TAG}^{} && \
git push origin --force $MINOR_TAG $MAJOR_TAG $FULL_TAG) || exit 3

0 comments on commit 9c9bcb0

Please sign in to comment.