Skip to content

test with permission #25

test with permission

test with permission #25

name: Trigger Deployed Repos Release
on:
push:
branches:
- test-multi-repo-release
env:
RELEASE_VERSION: "v2.8"
COMMIT_DATE: "2024-10-25 23:59:00" # Time in UTC
WORKFLOW_FILE: "release.yml"
jobs:
trigger-release:
runs-on: ubuntu-latest
strategy:
matrix:
repo: [
"gridsuite/spreadsheet-config-server",
"powsybl/powsybl-network-conversion-server"
]
permissions:
actions: write
steps:
- name: Get Commit SHA for Repository ${{ matrix.repo }}
id: get-sha
run: |
REPO="${{ matrix.repo }}"
COMMIT_DATE="${{ env.COMMIT_DATE }}"
# Create a temporary directory to fetch latest commit SHA before COMMIT_DATE
mkdir temp_repo
cd temp_repo
git init -q
git remote add origin https://github.com/${REPO}.git
git fetch origin main
# Get the latest commit SHA before COMMIT_DATE
COMMIT_SHA=$(git rev-list -1 --before="${COMMIT_DATE}" origin/main)
if [ -z "$COMMIT_SHA" ]; then
echo "No commit found before ${COMMIT_DATE} in ${REPO}"
exit 1
fi
echo "Latest commit SHA in ${REPO} before ${COMMIT_DATE}: ${COMMIT_SHA}"
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
# Clean up
cd ..
rm -rf temp_repo
- name: Trigger Release Workflow in ${{ matrix.repo }}
uses: actions/github-script@v6
with:
script: |
const [owner, repo] = "${{ matrix.repo }}".split("/");
const commitSHA = "${{ steps.get-sha.outputs.commit_sha }}";
await github.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id: process.env.WORKFLOW_FILE,
ref: 'main',
inputs: {
releaseVersion: process.env.RELEASE_VERSION,
gitReference: commitSHA
}
});
console.log(`Triggered release for ${owner}/${repo} with commit SHA: ${commitSHA}`);
console.log(response.data);
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}